33from functools import cached_property
44
55from apify_client ._client_registry import ClientRegistry , ClientRegistryAsync
6- from apify_client ._config import ClientConfig
7- from apify_client ._http_clients import HttpClient , HttpClientAsync
6+ from apify_client ._consts import (
7+ API_VERSION ,
8+ DEFAULT_API_URL ,
9+ DEFAULT_MAX_RETRIES ,
10+ DEFAULT_MIN_DELAY_BETWEEN_RETRIES_MILLIS ,
11+ DEFAULT_TIMEOUT_SECS ,
12+ )
13+ from apify_client ._http_clients import AsyncHttpClient , SyncHttpClient
814from apify_client ._resource_clients import (
915 ActorClient ,
1016 ActorClientAsync ,
@@ -71,11 +77,11 @@ def __init__(
7177 self ,
7278 token : str | None = None ,
7379 * ,
74- api_url : str | None = None ,
75- api_public_url : str | None = None ,
76- max_retries : int | None = 8 ,
77- min_delay_between_retries_millis : int | None = 500 ,
78- timeout_secs : int | None = 360 ,
80+ api_url : str = DEFAULT_API_URL ,
81+ api_public_url : str | None = DEFAULT_API_URL ,
82+ max_retries : int = DEFAULT_MAX_RETRIES ,
83+ min_delay_between_retries_millis : int = DEFAULT_MIN_DELAY_BETWEEN_RETRIES_MILLIS ,
84+ timeout_secs : int = DEFAULT_TIMEOUT_SECS ,
7985 ) -> None :
8086 """Initialize a new instance.
8187
@@ -84,26 +90,37 @@ def __init__(
8490 api_url: The URL of the Apify API server to which to connect. Defaults to https://api.apify.com. It can
8591 be an internal URL that is not globally accessible, in such case `api_public_url` should be set as well.
8692 api_public_url: The globally accessible URL of the Apify API server. It should be set only if the `api_url`
87- is an internal URL that is not globally accessible.
93+ is an internal URL that is not globally accessible. Defaults to https://api.apify.com.
8894 max_retries: How many times to retry a failed request at most.
8995 min_delay_between_retries_millis: How long will the client wait between retrying requests
9096 (increases exponentially from this value).
9197 timeout_secs: The socket timeout of the HTTP requests sent to the Apify API.
9298 """
93- self ._config = ClientConfig .from_user_params (
94- token = token ,
95- api_url = api_url ,
96- api_public_url = api_public_url ,
97- max_retries = max_retries ,
98- min_delay_between_retries_millis = min_delay_between_retries_millis ,
99- timeout_secs = timeout_secs ,
100- )
101- """Resolved client configuration."""
99+ # We need to do this because of mocking in tests and default mutable arguments.
100+ api_url = DEFAULT_API_URL if api_url is None else api_url
101+ api_public_url = DEFAULT_API_URL if api_public_url is None else api_public_url
102+
103+ self ._token = token
104+ """Apify API token for authentication."""
105+
106+ self ._base_url = f'{ api_url .rstrip ("/" )} /{ API_VERSION } '
107+ """Base URL of the Apify API."""
108+
109+ self ._public_base_url = f'{ api_public_url .rstrip ("/" )} /{ API_VERSION } '
110+ """Public base URL for CDN access."""
102111
103112 self ._statistics = ClientStatistics ()
104113 """Collector for client request statistics."""
105114
106- self ._http_client = HttpClient (config = self ._config , statistics = self ._statistics )
115+ self ._http_client = SyncHttpClient (
116+ token = token ,
117+ timeout_secs = timeout_secs or DEFAULT_TIMEOUT_SECS ,
118+ max_retries = max_retries or DEFAULT_MAX_RETRIES ,
119+ min_delay_between_retries_millis = (
120+ min_delay_between_retries_millis or DEFAULT_MIN_DELAY_BETWEEN_RETRIES_MILLIS
121+ ),
122+ statistics = self ._statistics ,
123+ )
107124 """HTTP client used to communicate with the Apify API."""
108125
109126 self ._client_registry = ClientRegistry (
@@ -130,16 +147,16 @@ def __init__(
130147 def _base_kwargs (self ) -> dict :
131148 """Base keyword arguments for resource client construction."""
132149 return {
133- 'base_url' : self ._config . base_url ,
134- 'public_base_url' : self ._config . public_base_url ,
150+ 'base_url' : self ._base_url ,
151+ 'public_base_url' : self ._public_base_url ,
135152 'http_client' : self ._http_client ,
136153 'client_registry' : self ._client_registry ,
137154 }
138155
139156 @property
140157 def token (self ) -> str | None :
141158 """The Apify API token used by the client."""
142- return self ._config . token
159+ return self ._token
143160
144161 def actor (self , actor_id : str ) -> ActorClient :
145162 """Retrieve the sub-client for manipulating a single Actor.
@@ -290,11 +307,11 @@ def __init__(
290307 self ,
291308 token : str | None = None ,
292309 * ,
293- api_url : str | None = None ,
294- api_public_url : str | None = None ,
295- max_retries : int | None = 8 ,
296- min_delay_between_retries_millis : int | None = 500 ,
297- timeout_secs : int | None = 360 ,
310+ api_url : str = DEFAULT_API_URL ,
311+ api_public_url : str | None = DEFAULT_API_URL ,
312+ max_retries : int = DEFAULT_MAX_RETRIES ,
313+ min_delay_between_retries_millis : int = DEFAULT_MIN_DELAY_BETWEEN_RETRIES_MILLIS ,
314+ timeout_secs : int = DEFAULT_TIMEOUT_SECS ,
298315 ) -> None :
299316 """Initialize a new instance.
300317
@@ -303,26 +320,37 @@ def __init__(
303320 api_url: The URL of the Apify API server to which to connect. Defaults to https://api.apify.com. It can
304321 be an internal URL that is not globally accessible, in such case `api_public_url` should be set as well.
305322 api_public_url: The globally accessible URL of the Apify API server. It should be set only if the `api_url`
306- is an internal URL that is not globally accessible.
323+ is an internal URL that is not globally accessible. Defaults to https://api.apify.com.
307324 max_retries: How many times to retry a failed request at most.
308325 min_delay_between_retries_millis: How long will the client wait between retrying requests
309326 (increases exponentially from this value).
310327 timeout_secs: The socket timeout of the HTTP requests sent to the Apify API.
311328 """
312- self ._config = ClientConfig .from_user_params (
313- token = token ,
314- api_url = api_url ,
315- api_public_url = api_public_url ,
316- max_retries = max_retries ,
317- min_delay_between_retries_millis = min_delay_between_retries_millis ,
318- timeout_secs = timeout_secs ,
319- )
320- """Resolved client configuration."""
329+ # We need to do this because of mocking in tests and default mutable arguments.
330+ api_url = DEFAULT_API_URL if api_url is None else api_url
331+ api_public_url = DEFAULT_API_URL if api_public_url is None else api_public_url
332+
333+ self ._token = token
334+ """Apify API token for authentication."""
335+
336+ self ._base_url = f'{ api_url .rstrip ("/" )} /{ API_VERSION } '
337+ """Base URL of the Apify API."""
338+
339+ self ._public_base_url = f'{ api_public_url .rstrip ("/" )} /{ API_VERSION } '
340+ """Public base URL for CDN access."""
321341
322342 self ._statistics = ClientStatistics ()
323343 """Collector for client request statistics."""
324344
325- self ._http_client = HttpClientAsync (config = self ._config , statistics = self ._statistics )
345+ self ._http_client = AsyncHttpClient (
346+ token = token ,
347+ timeout_secs = timeout_secs or DEFAULT_TIMEOUT_SECS ,
348+ max_retries = max_retries or DEFAULT_MAX_RETRIES ,
349+ min_delay_between_retries_millis = (
350+ min_delay_between_retries_millis or DEFAULT_MIN_DELAY_BETWEEN_RETRIES_MILLIS
351+ ),
352+ statistics = self ._statistics ,
353+ )
326354 """HTTP client used to communicate with the Apify API."""
327355
328356 self ._client_registry = ClientRegistryAsync (
@@ -349,16 +377,16 @@ def __init__(
349377 def _base_kwargs (self ) -> dict :
350378 """Base keyword arguments for resource client construction."""
351379 return {
352- 'base_url' : self ._config . base_url ,
353- 'public_base_url' : self ._config . public_base_url ,
380+ 'base_url' : self ._base_url ,
381+ 'public_base_url' : self ._public_base_url ,
354382 'http_client' : self ._http_client ,
355383 'client_registry' : self ._client_registry ,
356384 }
357385
358386 @property
359387 def token (self ) -> str | None :
360388 """The Apify API token used by the client."""
361- return self ._config . token
389+ return self ._token
362390
363391 def actor (self , actor_id : str ) -> ActorClientAsync :
364392 """Retrieve the sub-client for manipulating a single Actor.
0 commit comments