HTTP Clients¶
Classes:
-
HTTPClient–A class for keeping track of data related to the API
-
HTTPAuthenticatedClient–A HTTPClient which has been authenticated for use on secured endpoints.
HTTPClient
¶
A class for keeping track of data related to the API
The following are accepted as keyword arguments and will be used to construct httpx HTTPClients internally:
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
``cookies``: A dictionary of cookies to be sent with every request
``headers``: A dictionary of headers to be sent with every request
``timeout``: The maximum amount of a time a request can take. API functions will raise
httpx.TimeoutException if this is exceeded.
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
but can be set to False for testing purposes.
``follow_redirects``: Whether or not to follow redirects. Default value is False.
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
Attributes:
-
raise_on_unexpected_status(bool) –Whether or not to raise an errors.UnexpectedStatus if the API returns a status code that was not documented in the source OpenAPI document. Can also be provided as a keyword argument to the constructor.
Methods:
-
with_headers–Get a new client matching this one with additional headers
-
with_cookies–Get a new client matching this one with additional cookies
-
with_timeout–Get a new client matching this one with a new timeout (in seconds)
-
with_resilience–Get a new client matching this one with resilience configuration
-
set_httpx_client–Manually set the underlying httpx.Client
-
get_or_create_httpx_client–Get the underlying httpx.Client, constructing a new one if not previously set
-
__enter__–Enter a context manager for self.client—you cannot enter twice (see httpx docs)
-
__exit__–Exit a context manager for internal httpx.Client (see httpx docs)
-
set_async_httpx_client–Manually set the underlying httpx.AsyncClient
-
get_or_create_async_httpx_client–Get the underlying httpx.AsyncClient, constructing a new one if not previously set
-
__aenter__–Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)
-
__aexit__–Exit a context manager for underlying httpx.AsyncClient (see httpx docs)
with_timeout
¶
Get a new client matching this one with a new timeout (in seconds)
with_resilience
¶
Get a new client matching this one with resilience configuration
set_httpx_client
¶
Manually set the underlying httpx.Client
NOTE: This will override any other settings on the client, including cookies, headers, and timeout.
get_or_create_httpx_client
¶
Get the underlying httpx.Client, constructing a new one if not previously set
__enter__
¶
Enter a context manager for self.client—you cannot enter twice (see httpx docs)
__exit__
¶
Exit a context manager for internal httpx.Client (see httpx docs)
set_async_httpx_client
¶
Manually set the underlying httpx.AsyncClient
NOTE: This will override any other settings on the client, including cookies, headers, and timeout.
get_or_create_async_httpx_client
¶
Get the underlying httpx.AsyncClient, constructing a new one if not previously set
__aenter__
async
¶
Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)
__aexit__
async
¶
Exit a context manager for underlying httpx.AsyncClient (see httpx docs)
HTTPAuthenticatedClient
¶
Bases: HTTPClient
A HTTPClient which has been authenticated for use on secured endpoints.
Inherits all functionality from HTTPClient and adds API key authentication.
The get_or_create_httpx_client and get_or_create_async_httpx_client methods inject the
API-Key header before constructing the underlying httpx client.
Attributes:
-
api_key–The API key to use for authentication
-
api_secret–The API secret used to sign the authenticated request.
-
auth_header_name(str) –The name of the Authorization header
Methods:
-
get_or_create_httpx_client–Get the underlying httpx.Client, constructing a new one if not previously set
-
get_or_create_async_httpx_client–Get the underlying httpx.AsyncClient, constructing a new one if not previously set