py-unhcr


Namepy-unhcr JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryWrapper for the public UNHCR API, with built-in functions to make things easier
upload_time2024-12-19 21:36:01
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT 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.
keywords unhcr api refugee asylum humanitarian
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.

## 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)

# 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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "py-unhcr",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "unhcr, api, refugee, asylum, humanitarian",
    "author": null,
    "author_email": "Luis Alfredo Chaparro Gomez <luis@chapi.dev>",
    "download_url": "https://files.pythonhosted.org/packages/58/ec/ec7b98afc719096c9561953e78b37a82e66c5e67e7e037a8e270f68f91de/py_unhcr-0.1.1.tar.gz",
    "platform": null,
    "description": "# UNHCR Wrapper\r\nThis is a wrapper for the UNHCR API. It is written in Python and uses the requests library to make HTTP requests to the API.\r\n\r\n## Usage\r\nTo 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\r\nwith the API. Here is an example:\r\n\r\n```python\r\nfrom py_unhcr import UNHCR\r\n\r\n# Create an instance of the UNHCR class\r\nunhcr = UNHCR()\r\n\r\n# Get asylum applicants from Afghanistan in 2020 and return the data as a DataFrame\r\ndata = unhcr.set_filter(coo=\"AFG\", year_from=2020).asylum_applications(dataframe=True)\r\n```\r\n\r\n# Using `@dataframe` decorator\r\nThe `@dataframe` decorator can be used to automatically convert the response data to a pandas DataFrame. Here is an example:\r\n\r\n```python       \r\nfrom py_unhcr import UNHCR, dataframe\r\n\r\nunhcr_client = UNHCR()\r\n\r\n\r\n@dataframe\r\ndef get_data():\r\n    data = unhcr_client.set_filter(coo=\"VEN\", year_from=2021).asylum_applications()\r\n    return data\r\n\r\n\r\ndata = get_data()\r\n```\r\n\r\n# How to plot data\r\nTo plot the data, you can use matplotlib. Here is an example:\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nfrom py_unhcr import UNHCR\r\n\r\nunhcr_client = UNHCR()\r\nunhcr = unhcr_client.set_filter(coo=\"VEN\", year_from=2000, year_to=2024, coa_all=True).asylum_applications(\r\n    dataframe=True)\r\n\r\n# Group by year and sum the 'applied' values\r\nyearly_data = unhcr.groupby('year')['applied'].sum()\r\n\r\n# Create the plot\r\nplt.figure(figsize=(12, 6))  # Increase figure size for better readability\r\nyearly_data.plot(kind='line', marker='o')\r\n\r\n# Title and labels\r\nplt.title('Total Applications Over the Years')\r\nplt.xlabel('Year')\r\nplt.ylabel('Total Applications')\r\n\r\n# Rotate x-axis labels for better readability\r\nplt.xticks(rotation=45)\r\n\r\n# Optional: Limit the number of x-axis labels to avoid crowding\r\nplt.xticks(ticks=range(min(yearly_data.index), max(yearly_data.index) + 1, 1))\r\n\r\n# Display year labels on each point\r\nfor x, y in zip(yearly_data.index, yearly_data):\r\n    plt.text(x, y, str(x), fontsize=10, ha='right', va='bottom')\r\n\r\n# Show the grid for better visibility\r\nplt.grid(True)\r\n\r\n# Show the plot\r\nplt.show()\r\n```\r\n\r\nThis would output a line plot showing the total number of applications over the years for the specified country.\r\n![Total Applications Over the Years](https://github.com/chapig/py-unhcr/blob/main/example/output.png)\r\n\r\n# This is a WIP\r\nThis 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.\r\n",
    "bugtrack_url": null,
    "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.",
    "summary": "Wrapper for the public UNHCR API, with built-in functions to make things easier",
    "version": "0.1.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/chapig/py-unhcr/issues",
        "Homepage": "https://github.com/chapig/py-unhcr"
    },
    "split_keywords": [
        "unhcr",
        " api",
        " refugee",
        " asylum",
        " humanitarian"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a87318353adacd48baa4cba9d0639e055c7d0a783e99a21521bc0eeed72abe5b",
                "md5": "0c3757a17c62c33414be9cc44bdb1562",
                "sha256": "86cd2a3d49006a2cedf6136293aa32fddd92e2f9bf6ada362bede5568136cf47"
            },
            "downloads": -1,
            "filename": "py_unhcr-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0c3757a17c62c33414be9cc44bdb1562",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6481,
            "upload_time": "2024-12-19T21:35:58",
            "upload_time_iso_8601": "2024-12-19T21:35:58.000418Z",
            "url": "https://files.pythonhosted.org/packages/a8/73/18353adacd48baa4cba9d0639e055c7d0a783e99a21521bc0eeed72abe5b/py_unhcr-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "58ecec7b98afc719096c9561953e78b37a82e66c5e67e7e037a8e270f68f91de",
                "md5": "310066b4bc09dc2fa22134eb7296ef66",
                "sha256": "7a9e9001bc3b9577882ac803b350a133deb12b13ffbda2c50bc8c9c81ed1d8ee"
            },
            "downloads": -1,
            "filename": "py_unhcr-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "310066b4bc09dc2fa22134eb7296ef66",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6358,
            "upload_time": "2024-12-19T21:36:01",
            "upload_time_iso_8601": "2024-12-19T21:36:01.290583Z",
            "url": "https://files.pythonhosted.org/packages/58/ec/ec7b98afc719096c9561953e78b37a82e66c5e67e7e037a8e270f68f91de/py_unhcr-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-19 21:36:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "chapig",
    "github_project": "py-unhcr",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "py-unhcr"
}
        
Elapsed time: 0.57351s