Skip to main content

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:

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:

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:

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:

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

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.

Metadata

Release files for py-unhcr 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-unhcr 0.1.2
File Size Uploaded
py_unhcr-0.1.2.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-unhcr 0.1.2
File Interpreter ABI Platform
py_unhcr-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / py_unhcr-0.1.2.tar.gz

Download URL py_unhcr-0.1.2.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5e0fa38183a7a3bc2bb28253288b3516e96966a6406ba0c9461166b7c61dbbf2
BLAKE2b-256 checksum
How to use checksums
cac75433da483ff6fb449672a1c7aab712bc88a1a6cb7d17316a702203d3020b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release files / py_unhcr-0.1.2-py3-none-any.whl

Download URL py_unhcr-0.1.2-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cfdac0b0318d4cc5de821d9b76a931d568b57f99ddabbffe8c5416fe7229f31c
BLAKE2b-256 checksum
How to use checksums
0ca10d3be9e313f8f01446a0bcaa042f6a058e835e514fd1eb2f63d64af91966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page