Skip to content

HttpClient

HttpClient

Bases: HttpClientBase[httpx.Request]

An HTTP client wrapping an httpx.AsyncClient.

__init__

__init__(httpx_client: httpx.AsyncClient, error_handler: ErrorHandler | None = None)

Parameters:

Name Type Description Default
httpx_client httpx.AsyncClient

The httpx async client.

required
error_handler ErrorHandler | None

An optional error handler. Defaults to StderrErrorHandler.

None

send async

send(
    request: Request[TResponse], auth: AuthMiddleware[httpx.Request] | None = None
) -> TResponse | None

Send a request.

Creates an httpx.Request based on the request, and if provided, authenticates it using the auth strategy.

Returns the result of mapping the response text using the request.map_response. If an exception is thrown at any stage, it's caught and handled by the error handler.

Parameters:

Name Type Description Default
request Request[TResponse]

The request to send.

required
auth AuthMiddleware[httpx.Request] | None

Optional auth middleware. Defaults to None.

None

Returns:

Type Description
TResponse | None

The parsed response if the request is successful; None otherwise.

HttpClientBase

Bases: Generic[TSubRequest], ABC

Base class for a service that sends HTTP requests.

send abstractmethod async

send(
    request: Request[TResponse], auth: AuthMiddleware[TSubRequest] | None = None
) -> TResponse | None

Send a request.

Parameters:

Name Type Description Default
request Request[TResponse]

The request to send.

required
auth AuthMiddleware[TSubRequest] | None

Optional auth middleware. Defaults to None.

None

Returns:

Type Description
TResponse | None

The parsed response if the request is successful; None otherwise.

TResponse module-attribute

TResponse = TypeVar('TResponse')

Invariant type variable for a generic response.

TSubRequest module-attribute

TSubRequest = TypeVar('TSubRequest')

Invariant type variable for a generic request.