Skip to main content

A Python client to easily interact with the FAO SWS REST APIs

Project description

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:

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

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:

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

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

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:

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

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

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:

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:

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

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sws_api_client-0.0.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sws_api_client-0.0.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file sws_api_client-0.0.2.tar.gz.

File metadata

  • Download URL: sws_api_client-0.0.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for sws_api_client-0.0.2.tar.gz
Algorithm Hash digest
SHA256 34043425ecf9f9023b270793efe1dcaf07400ef6db62f0c451cbe88626de5334
MD5 df59fa03bae1edd446ecb47b9de5ed49
BLAKE2b-256 28ef362125107ef87f960020e8c068c0fa17181a685e9eedbf5ffb62dbb37d96

See more details on using hashes here.

File details

Details for the file sws_api_client-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: sws_api_client-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for sws_api_client-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 565b99f94c97051c6725813b3446a3facb4b4bb7160d6164bf98b09d4f9436f7
MD5 04c4e9ce958e8cb93b289ee6ddefbd19
BLAKE2b-256 8672d113cd6d90c4ca92e882bd4daa814774aa6ed06a5c8f589763415c08a3e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page