Skip to content

http

Async HTTP request client implementation built on httpx.

Client

Base class for HTTP clients.

client = Client()
response = await client.request("GET", "/some/resource")
assert response.status_code == 200

close async classmethod

close()

Close underlying client transport and proxies.

json

json(response)

Parse response as JSON.

Abstracts deserializing to allow for optional unwrapping of server response, e.g., {"data": []}.

Parameters:

Name Type Description Default
response httpx.Response

Response object, we call .json() on it.

required

Returns:

Type Description
Any

The result of httpx.Response.json() after passing through self.unwrap_json().

request async

request(*args, **kwargs)

Make a HTTP request.

Passes *args, **kwargs straight through to httpx.AsyncClient.request, we call raise_for_status() on the response and wrap any HTTPX error in a ClientException.

Parameters:

Name Type Description Default
*args Any

Unpacked into httpx.AsyncClient.request().

()
**kwargs Any

Unpacked into httpx.AsyncClient.request().

{}

Returns:

Type Description
httpx.Response

Return value of httpx.AsyncClient.request() after calling

httpx.Response

httpx.Response.raise_for_status()

Raises:

Type Description
ClientException

Wraps any httpx.HTTPError arising from the request or response status check.

unwrap_json staticmethod

unwrap_json(data)

Receive parsed JSON.

Override this method for pre-processing response data, for example unwrapping enveloped data.

Parameters:

Name Type Description Default
data Any

Value returned from response.json().

required

Returns:

Type Description
Any

Pre-processed data, default is pass-through/no-op.

ClientException

Bases: Exception

Base client exception.