sws-api-client


Namesws-api-client JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://bitbucket.org/cioapps/sws-it-python-api-client/src/main/
SummaryA Python client to easily interact with the FAO SWS REST APIs
upload_time2024-02-26 10:08:31
maintainer
docs_urlNone
authorMansillo, Daniele (CSI)
requires_python
license
keywords python fao sws rest api client
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# SWS API Client

This library provides the user with a set of useful tools to easily interact with the FAO SWS (Statistical Working System) REST APIs.

## Installation

The module is available on Pypi:

```bash
python -m pip install sws_api_client
```

The library requires Python 3.11+.

## Usage

To use the package the user needs to create an instance of the SwsApiClient class, provide it with the necessary parameters and execute the methods to query the specific endpoints.  

### Instantiate the client locally

There are three methods to instantiate the client:

#### 1. Pass the `sws_endpoint` and the `access_token` to the constructor

```python
from sws_api_client import SwsApiClient

sws_client = SwsApiClient(sws_endpoint="<sws_endpoint>", access_token="<access_token>")
```

#### 2. Pass to `sws_endpoint` and the `access_token` as named arguments

We need to execute the script from command line passing `--sws_endpoint` and `--access_token` as arguments:

```bash
python script.py --sws_endpoint <endpoint> --access_token <test_access_token>
```

And instantiate the client in our script with the class method `from_args`:

```python
from sws_api_client import SwsApiClient

sws_client = SwsApiClient.from_args()
```

#### 3. Create a conf file where to store the arguments

We need to create a conf file (default name: `"conf_sws_api_client.json"`) with the following structure:

```json
{
    "sws_endpoint": "<sws_endpoint>",
    "access_token": "<access_token>"
}
```

And instantiate the client in our script with the class method `from_conf`:

```python
from sws_api_client import SwsApiClient

sws_client = SwsApiClient.from_conf(conf_file="<conf_file_path>")

# Or, if the conf_file is named "conf_sws_api_client.json" and is in the current working directory

sws_client = SwsApiClient.from_conf()
```

### Instantiate the client in a SWS plugin

When working withing a SWS plugin instantiate the client as:

```python
from sws_api_client import SwsApiClient

sws_client = SwsApiClient.from_env()
```

### Perform requests

To perform requests you just need to call the available methods using the SwsApiClient object, as an example:

```python
dataset_details = sws_client.get_dataset_export_details(dataset_id="<dataset_id>")
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://bitbucket.org/cioapps/sws-it-python-api-client/src/main/",
    "name": "sws-api-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,fao,sws,rest,api,client",
    "author": "Mansillo, Daniele (CSI)",
    "author_email": "<daniele.mansillo@fao.com>",
    "download_url": "https://files.pythonhosted.org/packages/28/ef/362125107ef87f960020e8c068c0fa17181a685e9eedbf5ffb62dbb37d96/sws_api_client-0.0.2.tar.gz",
    "platform": null,
    "description": "\n# SWS API Client\n\nThis library provides the user with a set of useful tools to easily interact with the FAO SWS (Statistical Working System) REST APIs.\n\n## Installation\n\nThe module is available on Pypi:\n\n```bash\npython -m pip install sws_api_client\n```\n\nThe library requires Python 3.11+.\n\n## Usage\n\nTo use the package the user needs to create an instance of the SwsApiClient class, provide it with the necessary parameters and execute the methods to query the specific endpoints.  \n\n### Instantiate the client locally\n\nThere are three methods to instantiate the client:\n\n#### 1. Pass the `sws_endpoint` and the `access_token` to the constructor\n\n```python\nfrom sws_api_client import SwsApiClient\n\nsws_client = SwsApiClient(sws_endpoint=\"<sws_endpoint>\", access_token=\"<access_token>\")\n```\n\n#### 2. Pass to `sws_endpoint` and the `access_token` as named arguments\n\nWe need to execute the script from command line passing `--sws_endpoint` and `--access_token` as arguments:\n\n```bash\npython script.py --sws_endpoint <endpoint> --access_token <test_access_token>\n```\n\nAnd instantiate the client in our script with the class method `from_args`:\n\n```python\nfrom sws_api_client import SwsApiClient\n\nsws_client = SwsApiClient.from_args()\n```\n\n#### 3. Create a conf file where to store the arguments\n\nWe need to create a conf file (default name: `\"conf_sws_api_client.json\"`) with the following structure:\n\n```json\n{\n    \"sws_endpoint\": \"<sws_endpoint>\",\n    \"access_token\": \"<access_token>\"\n}\n```\n\nAnd instantiate the client in our script with the class method `from_conf`:\n\n```python\nfrom sws_api_client import SwsApiClient\n\nsws_client = SwsApiClient.from_conf(conf_file=\"<conf_file_path>\")\n\n# Or, if the conf_file is named \"conf_sws_api_client.json\" and is in the current working directory\n\nsws_client = SwsApiClient.from_conf()\n```\n\n### Instantiate the client in a SWS plugin\n\nWhen working withing a SWS plugin instantiate the client as:\n\n```python\nfrom sws_api_client import SwsApiClient\n\nsws_client = SwsApiClient.from_env()\n```\n\n### Perform requests\n\nTo perform requests you just need to call the available methods using the SwsApiClient object, as an example:\n\n```python\ndataset_details = sws_client.get_dataset_export_details(dataset_id=\"<dataset_id>\")\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A Python client to easily interact with the FAO SWS REST APIs",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://bitbucket.org/cioapps/sws-it-python-api-client/src/main/"
    },
    "split_keywords": [
        "python",
        "fao",
        "sws",
        "rest",
        "api",
        "client"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8672d113cd6d90c4ca92e882bd4daa814774aa6ed06a5c8f589763415c08a3e4",
                "md5": "04c4e9ce958e8cb93b289ee6ddefbd19",
                "sha256": "565b99f94c97051c6725813b3446a3facb4b4bb7160d6164bf98b09d4f9436f7"
            },
            "downloads": -1,
            "filename": "sws_api_client-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "04c4e9ce958e8cb93b289ee6ddefbd19",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4155,
            "upload_time": "2024-02-26T10:08:29",
            "upload_time_iso_8601": "2024-02-26T10:08:29.811808Z",
            "url": "https://files.pythonhosted.org/packages/86/72/d113cd6d90c4ca92e882bd4daa814774aa6ed06a5c8f589763415c08a3e4/sws_api_client-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "28ef362125107ef87f960020e8c068c0fa17181a685e9eedbf5ffb62dbb37d96",
                "md5": "df59fa03bae1edd446ecb47b9de5ed49",
                "sha256": "34043425ecf9f9023b270793efe1dcaf07400ef6db62f0c451cbe88626de5334"
            },
            "downloads": -1,
            "filename": "sws_api_client-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "df59fa03bae1edd446ecb47b9de5ed49",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3856,
            "upload_time": "2024-02-26T10:08:31",
            "upload_time_iso_8601": "2024-02-26T10:08:31.651741Z",
            "url": "https://files.pythonhosted.org/packages/28/ef/362125107ef87f960020e8c068c0fa17181a685e9eedbf5ffb62dbb37d96/sws_api_client-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-26 10:08:31",
    "github": false,
    "gitlab": false,
    "bitbucket": true,
    "codeberg": false,
    "bitbucket_user": "cioapps",
    "bitbucket_project": "sws-it-python-api-client",
    "lcname": "sws-api-client"
}
        
Elapsed time: 0.27092s