client

Client classes for connecting to the ParityOS cloud services API.

class parityos.services.client.JsonResponse(*args, **kwargs)

Bases: Protocol

Interface for a response class that has a json attribute.

class parityos.services.client.Client

Bases: ABC

Interface for clients that handle communication with a remote API by sending requests and receiving responses.

parityos.services.client.normalize_host_url(host_url: str) str

Normalize host url.

  • Add “https” protocol if no protocol is given.

  • Make sure urls with non-zero path have trailing “/” (no trailing slash means the url

    terminates in a file without a file ending).

Parameters:

host_url – URL of the API host.

Returns:

The correctly formatted host_url as a string

parityos.services.client.validate_host_url(_self, _attr, host_url: str)

Validate the host url for valid format and content.

Parameters:

host_url – URL of the API host.

Raises:

ParityOSAuthError – If the host url’s protocol is not “https” or the host url’s protocol is not “http” when using local host or the url is not of the format “https://domain.suffix</path>”.

class parityos.services.client.HTTPClient(authenticator: Authenticator, host_url: str = 'https://api.parityqc.com', api_version: int = 3, http_retries: int = 3, http_timeout: int = 10, http_backoff_factor: float = 0.02)

Bases: Client

Client class that sets up HTTP parameters (authentication, API endpoints, and so on).

Authentication with the remote API is handled by an Authenticator object, which provides means of obtaining a header authentication token from the API at a specified authentication endpoint which the client class provides.

Different Authenticators may differ in the way they fetch or query for credentials and what kind of request they send.

Example

>>> client = HTTPClient(InteractiveAuthenticator("my_parityos_username"))
authenticator: Authenticator

Authenticator instance that handles login and authentication token retrieval.

host_url: str

//api.parityqc.com”.

Type:

URL of the API host. Defaults to “https

api_version: int

Version of the api to access, which gets appended to the host URL for all API calls. Defaults to 3.

http_retries: int

Number of http retries before failing a request. Defaults to 3.

http_timeout: int

Maximum time in seconds to wait for a http response. Defaults to 10.

base_url: str

Host url including version path.

This base url is used for appending any endpoints.

Example: https://api.parityqc.com/v3/

auth_url: str

Endpoint url for authentication request.

send_request(method: HTTPMethod, endpoint: str, data: dict[str, Any] | None = None) Response

Send an HTTP request.

Parameters:
  • method – Request method to use (GET, POST, PUT, … ).

  • endpoint – Target endpoint url.

  • data – Payload data as a dictionary.

Returns:

The response from the request.

Raises:

ParityOSRequestError – If request is unsuccessful or returns an error response.