Client

Kelvin API Client.

This module provides synchronous and asynchronous clients for interacting with the Kelvin platform REST API (API version 3).

Example

>>> from kelvin.api.client import Client
>>> client = Client()
>>> assets = client.assets.list()

Client Implementation

Kelvin API Client.

class kelvin.api.client.client.Client(*, url=None, username=None, client_id=None, client_secret=None, password=None, totp=None, access_token=None, retries=None, timeout=None, verbose=None, plugins=None)[source]

Bases: SyncBaseClient

Kelvin API Client.

Synchronous client for interacting with the Kelvin API.

Parameters:
__dir__()[source]

Return list of available attributes.

Return type:

list[str]

Returns:

A list of attribute names including API model names.

__getattr__(name)[source]

Get an attribute or API model proxy.

Parameters:

name (str) – The attribute name to access.

Return type:

object

Returns:

A DataModelProxy for API models, or the attribute value.

class kelvin.api.client.client.AsyncClient(*, url=None, username=None, client_id=None, client_secret=None, password=None, totp=None, access_token=None, retries=None, timeout=None, verbose=None, plugins=None)[source]

Bases: AsyncBaseClient

Kelvin API Async Client.

Asynchronous client for interacting with the Kelvin API.

Parameters:
__dir__()[source]

Return list of available attributes.

Return type:

list[str]

Returns:

A list of attribute names including async API model names.

__getattr__(name)[source]

Get an attribute or async API model proxy.

Parameters:

name (str) – The attribute name to access.

Return type:

object

Returns:

An AsyncDataModelProxy for API models, or the attribute value.

HTTP Tools

HTTP Tools Module.

This module provides classes for storing and managing HTTP tools.

class kelvin.api.base.http_tools.ResponseHistory(maxlen=100)[source]

A history of HTTP responses.

This class provides methods to retrieve information about the responses stored in the history, such as status codes, successful responses, and error responses.

Parameters:

maxlen (int)

get_status_codes()[source]

Get a list of all status codes from stored responses.

Return type:

list[int]

Returns:

A list of HTTP status codes from all stored responses.

get_successful_responses()[source]

Get all successful responses (status codes 2xx).

Return type:

list[Response]

Returns:

A list of T objects with successful status codes.

get_error_responses()[source]

Get all error responses (status codes 4xx and 5xx).

Return type:

list[Response]

Returns:

A list of T objects with error status codes.

filter_by_status_code(status_code)[source]

Filter responses by a specific status code.

Parameters:

status_code (int) – The HTTP status code to filter by.

Return type:

list[Response]

Returns:

A list of T objects matching the status code.

filter_by_url_pattern(pattern)[source]

Filter responses by URL pattern.

Parameters:

pattern (str) – A string pattern to match in the request URL.

Return type:

list[Response]

Returns:

A list of T objects whose request URLs contain the pattern.

class kelvin.api.base.http_tools.RequestHistory(maxlen=100)[source]

A history of HTTP requests.

This class provides methods to retrieve information about the requests stored in the history, such as status codes, successful responses, and error responses.

Parameters:

maxlen (int)

Errors

Errors.

kelvin.api.base.error.lower(x, skip=True)[source]

Lower data to a json-ready representation.

Return type:

object

Parameters:
exception kelvin.api.base.error.ClientError[source]

General exception

exception kelvin.api.base.error.AuthenticationError[source]

Authentication exception

exception kelvin.api.base.error.LoginError[source]

Login exception

exception kelvin.api.base.error.LogoutError[source]

Logout exception

exception kelvin.api.base.error.APIError(response, errors=None)[source]

API Error.

Parameters:
  • response (Response)

  • errors (list[DataModel])

Return type:

None

classmethod from_response(response)[source]

Create API error from response.

Return type:

APIError

Parameters:

response (Response)

__init__(response, errors=None)[source]

Initialise API error.

Parameters:
  • response (Response)

  • errors (list[DataModel] | None)

Return type:

None

exception kelvin.api.base.error.ResponseError(message, response)[source]

Response error.

Parameters:
  • message (str)

  • response (Response)

Return type:

None

__init__(message, response)[source]

Initialise error.

Parameters:
  • message (str)

  • response (Response)

Return type:

None