Misc

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(*args, **kw)

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().

402:

The request failed because your account does not have a valid payment method. Check response.json()[‘reason’] for more information.

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(*args, **kw)

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().

402:

The request failed because your account does not have a valid payment method. Check response.json()[‘reason’] for more information.

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 route(path=None, method=None, **params)

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().

402:

The request failed because your account does not have a valid payment method. Check response.json()[‘reason’] for more information.

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

To run our analyzes, the KxY backend needs your data. The methods below are the only methods involved in sharing your data with us. The kxy package only uploads your data if and when needed.

kxy.api.data_transfer.generate_upload_url(identifier)

Requests a pre-signed URL to upload a dataset.

Parameters

identifier (str) – A string that uniquely identifies the content of the file.

Returns

d – The dictionary containing the pre-signed url.

Return type

dict or None

kxy.api.data_transfer.upload_data(df)

Updloads a dataframe to kxy servers.

Parameters

df (pd.DataFrame) – The dataframe to upload.

Returns

d – Whether the upload was successful.

Return type

bool

kxy.api.utils.approx_opt_remaining_time(step)

Estimate the amount of time left for the API to finish a task that requires maximum-entropy optimization.

Parameters

step (int) – A string that uniquely identifies the content of the file.

Returns

remaining_time – The approximate remaining duration.

Return type

str