HttpClient
Hierarchy
- HttpClientBase
- HttpClient
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 exponential timeout growth across retries.
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
call
Make an HTTP request.
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 in this request.
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: Any = 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, andno_timeoutdisables the timeout entirely.
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
Abstract base class for synchronous HTTP clients used by
ApifyClient.Extend this class to create a custom synchronous HTTP client. Override the
callmethod with your implementation. Helper methods from the base class are available for request preparation, URL building, and parameter parsing.Implementations must send the client's default headers from
self._headerswith every request, otherwise theAuthorizationheader never reaches the API. The_prepare_request_callhelper merges them into the per-request headers automatically.