HttpClientBase
Hierarchy
- HttpClientBase
Index
Methods
__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. Set to 0 to disable retries.
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-onlyuser_agent_suffix: (str | list[str]) | None = None
Extra part or parts appended to the default
User-Agentheader, separated by;.optionalkeyword-onlyhttp_compressor: HttpCompressor | None = None
Compressor used to compress request bodies. Defaults to
GzipHttpCompressor.
Returns None
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
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
Properties
stats
Statistics about API client usage and rate limit errors.
Shared configuration and utilities for HTTP clients.
Provides common functionality for both sync and async HTTP clients including: header construction, parameter parsing, request body preparation, URL building, timeout calculation, and error classification.
Subclasses should call
super().__init__()to initialize shared configuration. The helpers are then used by the inheritedcall, and stay available to a client that replaces it.