Metadata-Version: 2.1
Name: py-unhcr
Version: 0.1.2
Summary: Wrapper for the public UNHCR API, with built-in functions to make things easier
Author-email: Luis Alfredo Chaparro Gomez <luis@chapi.dev>
License: MIT License
        
        Copyright (c) 2024 Luis Alfredo Chaparro Gomez
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/chapig/py-unhcr
Project-URL: Bug Tracker, https://github.com/chapig/py-unhcr/issues
Keywords: unhcr,api,refugee,asylum,humanitarian
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.25.0
Requires-Dist: pandas>=1.0.0

# UNHCR Wrapper
This is a wrapper for the UNHCR API. It is written in Python and uses the requests library to make HTTP requests to the API.

## Installation

You can install the package using pip:

```bash
pip install py-unhcr
```

## Usage
To use the wrapper, you need to import the `UNHCR` class and create an instance of it. You can then use the methods provided by the class to interact
with the API. Here is an example:

```python
from py_unhcr import UNHCR

# Create an instance of the UNHCR class
unhcr = UNHCR()

# Get asylum applicants from Afghanistan in 2020 and return the data as a DataFrame
data = unhcr.set_filter(coo="AFG", year_from=2020).asylum_applications(dataframe=True)
```

# Using `@dataframe` decorator
The `@dataframe` decorator can be used to automatically convert the response data to a pandas DataFrame. Here is an example:

```python       
from py_unhcr import UNHCR, dataframe

unhcr_client = UNHCR()


@dataframe
def get_data():
    data = unhcr_client.set_filter(coo="VEN", year_from=2021).asylum_applications()
    return data


data = get_data()
```

# How to plot data
To plot the data, you can use matplotlib. Here is an example:

```python
import matplotlib.pyplot as plt
from py_unhcr import UNHCR

unhcr_client = UNHCR()
unhcr = unhcr_client.set_filter(coo="VEN", year_from=2000, year_to=2024, coa_all=True).asylum_applications(
    dataframe=True)

# Group by year and sum the 'applied' values
yearly_data = unhcr.groupby('year')['applied'].sum()

# Create the plot
plt.figure(figsize=(12, 6))  # Increase figure size for better readability
yearly_data.plot(kind='line', marker='o')

# Title and labels
plt.title('Total Applications Over the Years')
plt.xlabel('Year')
plt.ylabel('Total Applications')

# Rotate x-axis labels for better readability
plt.xticks(rotation=45)

# Optional: Limit the number of x-axis labels to avoid crowding
plt.xticks(ticks=range(min(yearly_data.index), max(yearly_data.index) + 1, 1))

# Display year labels on each point
for x, y in zip(yearly_data.index, yearly_data):
    plt.text(x, y, str(x), fontsize=10, ha='right', va='bottom')

# Show the grid for better visibility
plt.grid(True)

# Show the plot
plt.show()
```

This would output a line plot showing the total number of applications over the years for the specified country.
![Total Applications Over the Years](https://github.com/chapig/py-unhcr/blob/main/example/output.png?raw=true)

# This is a WIP
This project is a work in progress and more features will be added in the future. If you have any suggestions or feedback, feel free to open an issue or submit a pull request.
