wuttatell.client

Simple API Client

class wuttatell.client.SimpleAPIClient(config, base_url=None, token=None, ssl_verify=None, max_retries=None)[source]

Simple client for “typical” API service.

This basically assumes telemetry can be submitted to a single API endpoint, and the request should contain an auth token.

Parameters:
  • config – App config object.

  • base_url – Base URL of the API.

  • token – Auth token for the API.

  • ssl_verify – Whether the SSL cert presented by the server should be verified. This is effectively true by default, but may be disabled for testing with self-signed certs etc.

  • max_retries – Maximum number of retries each connection should attempt. This value is ultimately given to the HTTPAdapter instance.

Most params may be omitted, if config specifies instead:

[wutta.api]
base_url = https://my.example.com/api
token = XYZPDQ12345
ssl_verify = false
max_retries = 5

Upon instantiation, session will be None until the first request is made. (Technically when init_session() first happens.)

session

requests.Session instance being used to make API requests.

get(api_method, params=None)[source]

Perform a GET request for the given API method, and return the response.

This calls make_request() for the heavy lifting.

Parameters:
  • api_method – API method endpoint to use, e.g. '/my/telemetry'

  • params – Dict of query string params for the request, if applicable.

Return type:

requests.Response instance.

init_session()[source]

Initialize the HTTP session with the API.

This method is invoked as part of make_request().

It first checks session and will skip if already initialized.

For initialization, it establishes a new requests.Session instance, and modifies it as needed per config.

make_request(request_method, api_method, params=None, data=None)[source]

Make a request to the API, and return the response.

This first calls init_session() to establish the session if needed.

Parameters:
  • request_method – HTTP request method; for now only 'GET' and 'POST' are supported.

  • api_method – API method endpoint to use, e.g. '/my/telemetry'

  • params – Dict of query string params for the request, if applicable.

  • data – Payload data for the request, if applicable. Should be JSON-serializable, e.g. a list or dict.

Return type:

requests.Response instance.

post(api_method, **kwargs)[source]

Perform a POST request for the given API method, and return the response.

This calls make_request() for the heavy lifting.

Parameters:

api_method – API method endpoint to use, e.g. '/my/telemetry'

Return type:

requests.Response instance.