Api

class perses_api.api.Api[source]

Bases: object

The class includes all necessary methods to access the Perses API

Parameters:

perses_api_model (APIModel) – Inject a Perses API model object that includes all necessary values and information

perses_api_model

This is where we store the perses_api_model

Type:

APIModel

__init__(perses_api_model: APIModel)[source]
call_the_api(api_call: str, method: RequestsMethods = RequestsMethods.GET, json_complete: str = None, response_status_code: bool = False) Any[source]

The method includes a functionality to execute a defined API call against the Perses endpoints

Parameters:
  • api_call (str) – Specify the API call path relative to the host

  • method (RequestsMethods) – Specify the HTTP method to use (default GET)

  • json_complete (str) – Specify the JSON-serialised request body for POST and PUT requests (default None)

  • response_status_code (bool) – Specify if the HTTP status code should be injected into the response dict (default False)

Raises:
  • ValueError – Missed specifying a necessary value

  • Exception – Unspecified error by executing the API call

Returns:

The API response as a parsed dict or list, or the raw httpx.Response for non-JSON responses

Return type:

any

create_the_http_api_client(headers: dict = None) Client | AsyncClient[source]

The method includes a functionality to create the HTTP client based on the API model configuration

Parameters:

headers (dict) – Specify the HTTP headers to attach to every request (default None)

Returns:

A configured sync or async httpx client

Return type:

Union[httpx.Client, httpx.AsyncClient]