HttpClientAsync
Hierarchy
- HttpClientBase
- HttpClientAsync
Index
Methods
__aenter__
Return this client and close it when the async context exits.
Returns Self
__aexit__
Close resources owned by the asynchronous HTTP client.
Parameters
exc_type: type[BaseException] | None
exc_value: BaseException | None
traceback: TracebackType | None
Returns None
__init__
Initialize the HTTP client base.
Parameters
optionalkeyword-onlytoken: str | None = None
Apify API token for authentication.
optionalkeyword-onlytimeout_short: timedelta = DEFAULT_TIMEOUT_SHORT
Default timeout for short-duration API operations (simple CRUD operations, ...).
optionalkeyword-onlytimeout_medium: timedelta = DEFAULT_TIMEOUT_MEDIUM
Default timeout for medium-duration API operations (batch operations, listing, ...).
optionalkeyword-onlytimeout_long: timedelta = DEFAULT_TIMEOUT_LONG
Default timeout for long-duration API operations (long-polling, streaming, ...).
optionalkeyword-onlytimeout_max: timedelta = DEFAULT_TIMEOUT_MAX
Maximum timeout cap for any single request attempt, including tier and per-call timeouts.
optionalkeyword-onlymax_retries: int = DEFAULT_MAX_RETRIES
Maximum number of retries for failed requests.
optionalkeyword-onlymin_delay_between_retries: timedelta = DEFAULT_MIN_DELAY_BETWEEN_RETRIES
Minimum delay between retries.
optionalkeyword-onlystatistics: ClientStatistics | None = None
Statistics tracker for API calls. Created automatically if not provided.
optionalkeyword-onlyheaders: dict[str, str] | None = None
Additional HTTP headers to include in all requests.
optionalkeyword-onlyhttp_compressor: HttpCompressor | None = None
Compressor used to compress request bodies. Defaults to
GzipHttpCompressor.
Returns None
aclose
Close resources owned by the asynchronous HTTP client.
Transports that own a connection pool or a session override it. The default does nothing.
Returns None
call
Make an HTTP request with automatic retry and exponential backoff.
Parameters
keyword-onlymethod: str
HTTP method (GET, POST, PUT, DELETE, etc.).
keyword-onlyurl: str
Full URL to make the request to.
optionalkeyword-onlyheaders: dict[str, str] | None = None
Additional headers to include.
optionalkeyword-onlyparams: dict[str, Any] | None = None
Query parameters to append to the URL.
optionalkeyword-onlydata: ((str | bytes) | bytearray) | None = None
Raw request body data. Cannot be used together with json.
optionalkeyword-onlyjson: JsonSerializable | None = None
JSON-serializable data for the request body. Cannot be used together with data.
optionalkeyword-onlystream: bool | None = None
Whether to stream the response body.
optionalkeyword-onlytimeout: Timeout = 'medium'
Timeout for the API HTTP request. Use
short,medium, orlongtier literals for preconfigured timeouts. Atimedeltaoverrides it for this call (capped attimeout_max), andno_timeoutdisables the timeout entirely.
Returns HttpResponse
The HTTP response object.
is_retryable_transport_error
Return whether an underlying HTTP-library exception is retryable.
The default classifies nothing as retryable, so a transport that doesn't override it gives up on the first connection failure. Every transport adapter should map its own transient error types here.
Parameters
exc: Exception
Returns bool
is_timeout_error
Return whether an exception represents a transport timeout.
Recognizes Python's own
TimeoutError. Transport adapters extend it with the timeout types their HTTP library defines.Parameters
exc: Exception
Returns bool
send_request
Send one request through the underlying HTTP library.
Required by the inherited
call, so a transport adapter must implement it. Overridingcallitself bypasses it entirely. Let the HTTP library's exceptions propagate unwrapped:callclassifies them throughis_retryable_transport_errorandis_timeout_error.Parameters
keyword-onlymethod: str
HTTP method (GET, POST, PUT, DELETE, etc.).
keyword-onlyurl: str
Full request URL, with the query parameters already encoded into it.
keyword-onlyheaders: dict[str, str]
Final request headers, with the client's default headers already merged in.
keyword-onlycontent: bytes | None
Request body, already serialized and compressed, or None for a request without a body.
keyword-onlytimeout: float | None
Timeout for this attempt in seconds, or None for no timeout at all.
keyword-onlystream: bool
Whether to return the response with the body unread, so the caller can stream it.
Returns HttpResponse
The HTTP response object.
set_default_authorization
Set the
Authorizationheader from the token, unless an authorization header is already configured.Parameters
token: str
The Apify API token to set as the
Bearerauthorization.
Returns None
Base class for asynchronous HTTP clients used by
ApifyClientAsync.Extend this class to create a custom asynchronous HTTP client. See
HttpClientfor details on the expected behavior.