Python API client

See Using the web API for a calculation example and service URLs.

Python client functions for harvesting results from the PyDIET ETC

class Client(api_url: str | None = None)[source]

Bases: object

Class for the Python client API.

Parameters:

api_url (str, optional) -- API root URL (defaults to "api_path" setting).

api_url

Root URL used for ETC requests.

Type:

str

Examples

>>> from .client import Client
>>> client = Client("https://etc.example/api")
>>> client.api_url
'https://etc.example/api'
query(query: ETCQueryModel, timeout: float = 10.0) → ETCResponseModel[source]

Query the ETC API.

Parameters:
  • query (ETCQueryModel) -- Validated ETC query. Its instrument field selects the endpoint; the remaining non-null fields are sent as query parameters.

  • timeout (float, optional) -- HTTP timeout in seconds.

Returns:

response (ETCResponseModel) -- Validated ETC response.

Raises:

RuntimeError -- If the request fails, the server returns an error response, the response is not JSON, or its JSON does not match the response model.