afnio.tellurio.client#

Functions

load_username()

Loads the username from a JSON configuration file.

save_username(username)

Saves the username to a JSON configuration file.

Classes

TellurioClient([base_url, port])

A client for interacting with the Tellurio backend.

Exceptions

InvalidAPIKeyError

Exception raised when the API key is invalid.

exception afnio.tellurio.client.InvalidAPIKeyError[source]#

Bases: Exception

Exception raised when the API key is invalid.

add_note()#

Exception.add_note(note) – add a note to the exception

args#
with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class afnio.tellurio.client.TellurioClient(base_url=None, port=None)[source]#

Bases: object

A client for interacting with the Tellurio backend.

This client provides methods for authenticating with the backend, making HTTP requests (GET, POST, DELETE), and verifying API keys. It is designed to simplify communication with the Tellurio platform.

delete(endpoint)[source]#

Makes a DELETE request to the specified endpoint.

Parameters:

endpoint (str) – The API endpoint (relative to the base URL).

Returns:

The HTTP response object.

Return type:

httpx.Response

get(endpoint)[source]#

Makes a GET request to the specified endpoint.

Parameters:

endpoint (str) – The API endpoint (relative to the base URL).

Returns:

The HTTP response object.

Return type:

httpx.Response

login(api_key=None, relogin=False)[source]#

Logs in the user using an API key and verifies its validity.

Credential resolution order:

  1. If api_key is provided, it is used.

  2. Otherwise, if the TELLURIO_API_KEY environment variable is set,

    it is used.

  3. Otherwise, if not relogin, attempts to load a stored API key from

    the keyring.

If authentication succeeds and the API key was provided directly (not via keyring), it is stored in the keyring for future use.

Parameters:
  • api_key (str, optional) – The user’s API key. If not provided, the method attempts to use the TELLURIO_API_KEY environment variable, then the keyring.

  • relogin (bool) – If True, forces a re-login and requires a new API key.

Returns:

A dictionary containing the user’s email and username.

Return type:

dict

Raises:

ValueError – If the API key is invalid or not provided during re-login.

patch(endpoint, json)[source]#

Makes a PATCH request to the specified endpoint.

Parameters:
  • endpoint (str) – The API endpoint (relative to the base URL).

  • json (dict) – The JSON payload to send in the request.

Returns:

The HTTP response object.

Return type:

httpx.Response

post(endpoint, json)[source]#

Makes a POST request to the specified endpoint.

Parameters:
  • endpoint (str) – The API endpoint (relative to the base URL).

  • json (dict) – The JSON payload to send in the request.

Returns:

The HTTP response object.

Return type:

httpx.Response

afnio.tellurio.client.load_username()[source]#

Loads the username from a JSON configuration file. This function reads the JSON file at the specified path and retrieves the username stored in it. If the file does not exist, it returns None.

afnio.tellurio.client.save_username(username)[source]#

Saves the username to a JSON configuration file. If the username is different from the one already stored, this function updates the ‘username’ field and clears all other preferences. Otherwise, it preserves all existing values.