Skip to content

Reference API

The following classes are exposed to the user:

httpx_tenacity

Provide top level symbols.

TenaciousTransport

Bases: BaseTransport

Define the synchronous tenacious (retrying) transport.

This transport consists of a composed transport for handling requests and an appropriately configured tenacity retrying instance.

__init__(*, retry: tenacity.Retrying, transport: httpx.BaseTransport, **kwargs: dict[str, object]) -> None

create(max_attempts: int = 5, multiplier: float = 1, max_wait_seconds: float | timedelta = 60, min_wait_seconds: float | timedelta = 0.02, exponent_base: float = 2, **kwargs: Unpack[HTTPXHTTPTransportKeywordArguments]) -> TenaciousTransport classmethod

Create an instance of a synchronous tenacious (retrying) transport.

This factory method constructs the instance with an underlying httpx.HTTPTransport. That transport is passed any additional keyword arguments.

The constructed transport retries requests when there are server-side issues and will either wait the time set in a Retry-After response header or use a random exponential backoff.

Parameters:

Name Type Description Default
max_attempts int

Maximum number of attempts.

5
multiplier float

Multiplier for the exponential backoff between retries.

1
max_wait_seconds float | timedelta

Maximum wait time between retries.

60
min_wait_seconds float | timedelta

Minimum wait time between retries.

0.02
exponent_base float

The base for the exponential backoff.

2
**kwargs Unpack[HTTPXHTTPTransportKeywordArguments]

Additional keyword arguments are used in the construction of an httpx.HTTPTransport.

{}

Returns:

Type Description
TenaciousTransport

A default instance of the class created from the given arguments.

handle_request(request: httpx.Request) -> httpx.Response

Handle a synchronous request with retrying.

AsyncTenaciousTransport

Bases: AsyncBaseTransport

Define the asynchronous tenacious (retrying) transport.

This transport consists of a composed transport for handling requests and an appropriately configured tenacity retrying instance.

__init__(*, retry: tenacity.AsyncRetrying, transport: httpx.AsyncBaseTransport, **kwargs: dict[str, object]) -> None

create(max_attempts: int = 5, multiplier: float = 1, max_wait_seconds: float | timedelta = 60, min_wait_seconds: float | timedelta = 0.02, exponent_base: float = 2, **kwargs: Unpack[HTTPXHTTPTransportKeywordArguments]) -> AsyncTenaciousTransport classmethod

Create an instance of an asynchronous tenacious (retrying) transport.

This factory method constructs the instance with an underlying httpx.AsyncHTTPTransport. That transport is passed any additional keyword arguments.

The constructed transport retries requests when there are server-side issues and will either wait the time set in a Retry-After response header or use a random exponential backoff.

Parameters:

Name Type Description Default
max_attempts int

Maximum number of attempts.

5
multiplier float

Multiplier for the exponential backoff between retries.

1
max_wait_seconds float | timedelta

Maximum wait time between retries.

60
min_wait_seconds float | timedelta

Minimum wait time between retries.

0.02
exponent_base float

The base for the exponential backoff.

2
**kwargs Unpack[HTTPXHTTPTransportKeywordArguments]

Additional keyword arguments are used in the construction of an httpx.AsyncHTTPTransport.

{}

Returns:

Type Description
AsyncTenaciousTransport

A default instance of the class created from the given arguments.

handle_async_request(request: httpx.Request) -> httpx.Response async

Handle an asynchronous request with retrying.