RESTful API Client

Python client for the KXY RESTful API.

class kxy.api.client.APIClient

Python client for the RESTful KXY API. All API methods require an API key. The API key must be set by running kxy configure from the terminal.

static get(path, **params)

Important

This method requires a valid API key.

Issues a GET request to the API resource identified by the input path.

Parameters:
  • path (str) – The relative path of the API resource.
  • params (dict, optional) – The query parameters of the GET request. Any keyword argument is automatically interpreted as a request parameter, its name is used as the parameter name, and its value as the parameter value.
Returns:

response – The response of the API. The request HTTP status code can be accessed through response.status_code. To check if the request was succesful, inspect response.ok. When the API returned data, they can be accessed through response.json(). Supported status codes are:

200:

The request was successful and the API returned some data accessible through response.json().

403:

The request failed because some parameter are either invalid or missing. Check response.json()[‘reason’] for more information.

404:

The request failed because the API couldn’t yet solve the problem of interest. You should typically try again another time. Check response.json()[‘reason’] for more information.

Return type:

requests.Response

static post(path, **params)

Important

This method requires a valid API key.

Issues a POST request to the API resource identified by the input path.

Parameters:
  • path (str) – The relative path of the API resource.
  • params (dict, optional) – The data to be submitted to the API as part of the POST request, as a JSON. Any keyword argument is automatically interpreted as a key of the JSON data that will be submitted to the API, and its value the associated value in the JSON.
Returns:

response – The response of the API. The request HTTP status code can be accessed through response.status_code. To check if the request was succesful, inspect response.ok. When the API returned data, they can be accessed through response.json().

Supported status codes are:

200:

The request was successful and the API returned some data accessible through response.json().

403:

The request failed because some parameter are either invalid or missing. Check response.json()[‘reason’] for more information.

404:

The request failed because the API couldn’t yet solve the problem of interest. You should typically try again another time. Check response.json()[‘reason’] for more information.

Return type:

requests.Response

route

Important

This method requires a valid API key.

Generic method to issue a GET or a POST request to the API resource identified by the input path.

Parameters:
  • path (str) – The relative path of the API resource.
  • method (str) – The REST method. Should be either ‘GET’ or ‘POST’.
  • params (dict, optional) – The data to be submitted to the API as a JSON for POST requests, or query parameters in the case of GET requests.
Returns:

response – The response of the API. The request HTTP status code can be accessed through response.status_code. To check if the request was succesful, inspect response.ok. When the API returned data, they can be accessed through response.json().

Supported status codes are:

200:

The request was successful and the API returned some data accessible through response.json().

403:

The request failed because some parameter are either invalid or missing. Check response.json()[‘reason’] for more information.

404:

The request failed because the API couldn’t yet solve the problem of interest. You should typically try again another time. Check response.json()[‘reason’] for more information.

Return type:

requests.Response

Raises:

ValueError – If path is None or method is neither ‘GET’, nor ‘POST’.

static stage()

Defines the deployment stage of the RESTful API the client should talk to.

Returns:v – The API stage to use.
Return type:str
static url(path)

Turns a relative path into a full API endpoint url.

Parameters:path (str) – The relative path of the API resource.
Returns:u – The full URL of the API resource.
Return type:str