1313from apify_client ._consts import (
1414 DEFAULT_MAX_RETRIES ,
1515 DEFAULT_MIN_DELAY_BETWEEN_RETRIES ,
16- DEFAULT_REQUEST_TIMEOUT ,
17- DEFAULT_REQUEST_TIMEOUT_MAX ,
16+ DEFAULT_TIMEOUT ,
17+ DEFAULT_TIMEOUT_LONG ,
18+ DEFAULT_TIMEOUT_MAX ,
19+ DEFAULT_TIMEOUT_SHORT ,
1820 Timeout ,
1921)
2022from apify_client ._docs import docs_group
@@ -90,8 +92,10 @@ def __init__(
9092 self ,
9193 * ,
9294 token : str | None = None ,
93- timeout : timedelta = DEFAULT_REQUEST_TIMEOUT ,
94- timeout_max : timedelta = DEFAULT_REQUEST_TIMEOUT_MAX ,
95+ timeout_short : timedelta = DEFAULT_TIMEOUT_SHORT ,
96+ timeout : timedelta = DEFAULT_TIMEOUT ,
97+ timeout_long : timedelta = DEFAULT_TIMEOUT_LONG ,
98+ timeout_max : timedelta = DEFAULT_TIMEOUT_MAX ,
9599 max_retries : int = DEFAULT_MAX_RETRIES ,
96100 min_delay_between_retries : timedelta = DEFAULT_MIN_DELAY_BETWEEN_RETRIES ,
97101 statistics : ClientStatistics | None = None ,
@@ -101,14 +105,18 @@ def __init__(
101105
102106 Args:
103107 token: Apify API token for authentication.
104- timeout: Initial request timeout.
108+ timeout_short: Timeout for fast CRUD operations (e.g., get, update, delete).
109+ timeout: Timeout for batch, list, and data transfer operations.
110+ timeout_long: Timeout for long-polling, streaming, and other heavy operations.
105111 timeout_max: Maximum timeout cap for exponential timeout growth across retries.
106112 max_retries: Maximum number of retries for failed requests.
107113 min_delay_between_retries: Minimum delay between retries.
108114 statistics: Statistics tracker for API calls. Created automatically if not provided.
109115 headers: Additional HTTP headers to include in all requests.
110116 """
117+ self ._timeout_short = timeout_short
111118 self ._timeout = timeout
119+ self ._timeout_long = timeout_long
112120 self ._timeout_max = timeout_max
113121 self ._max_retries = max_retries
114122 self ._min_delay_between_retries = min_delay_between_retries
@@ -133,6 +141,45 @@ def __init__(
133141
134142 self ._headers = {** default_headers , ** (headers or {})}
135143
144+ @property
145+ def timeout_short (self ) -> timedelta :
146+ """Timeout for fast CRUD operations (e.g., get, update, delete)."""
147+ return self ._timeout_short
148+
149+ @property
150+ def timeout (self ) -> timedelta :
151+ """Timeout for batch, list, and data transfer operations."""
152+ return self ._timeout
153+
154+ @property
155+ def timeout_long (self ) -> timedelta :
156+ """Timeout for long-polling, streaming, and other heavy operations."""
157+ return self ._timeout_long
158+
159+ @property
160+ def timeout_max (self ) -> timedelta :
161+ """Maximum timeout cap for exponential timeout growth across retries."""
162+ return self ._timeout_max
163+
164+ def _resolve_timeout (self , timeout : Timeout ) -> timedelta | None :
165+ """Resolve a timeout tier literal or value to a concrete timedelta.
166+
167+ Args:
168+ timeout: The timeout specification to resolve.
169+
170+ Returns:
171+ A `timedelta` for tier literals and explicit values, `None` for `'no_timeout'`.
172+ """
173+ if timeout == 'no_timeout' :
174+ return None
175+ if timeout == 'short' :
176+ return self ._timeout_short
177+ if timeout == 'default' :
178+ return self ._timeout
179+ if timeout == 'long' :
180+ return self ._timeout_long
181+ return timeout
182+
136183 @staticmethod
137184 def _parse_params (params : dict [str , Any ] | None ) -> dict [str , Any ] | None :
138185 """Convert request parameters to Apify API-compatible formats.
@@ -221,7 +268,7 @@ def call(
221268 data : str | bytes | bytearray | None = None ,
222269 json : Any = None ,
223270 stream : bool | None = None ,
224- timeout : Timeout = None ,
271+ timeout : Timeout = 'default' ,
225272 ) -> HttpResponse :
226273 """Make an HTTP request.
227274
@@ -233,8 +280,9 @@ def call(
233280 data: Raw request body data. Cannot be used together with json.
234281 json: JSON-serializable data for the request body. Cannot be used together with data.
235282 stream: Whether to stream the response body.
236- timeout: Timeout for the API HTTP request. `None` uses the timeout configured on the client,
237- a `timedelta` overrides it for this call, and `'no_timeout'` disables the timeout entirely.
283+ timeout: Timeout for the API HTTP request.
284+ Use `'short'`, `'default'`, or `'long'` tier literals for preconfigured timeouts.
285+ A `timedelta` overrides it for this call, and `'no_timeout'` disables the timeout entirely.
238286
239287 Returns:
240288 The HTTP response object.
@@ -264,7 +312,7 @@ async def call(
264312 data : str | bytes | bytearray | None = None ,
265313 json : Any = None ,
266314 stream : bool | None = None ,
267- timeout : Timeout = None ,
315+ timeout : Timeout = 'default' ,
268316 ) -> HttpResponse :
269317 """Make an HTTP request.
270318
@@ -276,8 +324,9 @@ async def call(
276324 data: Raw request body data. Cannot be used together with json.
277325 json: JSON-serializable data for the request body. Cannot be used together with data.
278326 stream: Whether to stream the response body.
279- timeout: Timeout for the API HTTP request. `None` uses the timeout configured on the client,
280- a `timedelta` overrides it for this call, and `'no_timeout'` disables the timeout entirely.
327+ timeout: Timeout for the API HTTP request.
328+ Use `'short'`, `'default'`, or `'long'` tier literals for preconfigured timeouts.
329+ A `timedelta` overrides it for this call, and `'no_timeout'` disables the timeout entirely.
281330
282331 Returns:
283332 The HTTP response object.
0 commit comments