Skip to content

Commit 996f1c5

Browse files
committed
New client commit
1 parent e094d6a commit 996f1c5

4 files changed

Lines changed: 30 additions & 16 deletions

File tree

src/apify/_actor.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -488,17 +488,21 @@ def new_client(
488488
(increases exponentially from this value).
489489
timeout: The socket timeout of the HTTP requests sent to the Apify API.
490490
"""
491-
token = token or self.configuration.token
492-
api_url = api_url or self.configuration.api_base_url
493-
return ApifyClientAsync(
494-
token=token,
495-
api_url=api_url,
496-
max_retries=max_retries,
497-
min_delay_between_retries_millis=int(min_delay_between_retries.total_seconds() * 1000)
498-
if min_delay_between_retries is not None
499-
else None,
500-
timeout_secs=int(timeout.total_seconds()) if timeout else None,
501-
)
491+
kwargs = {
492+
'token': token or self.configuration.token,
493+
'api_url': api_url or self.configuration.api_base_url,
494+
}
495+
496+
if max_retries is not None:
497+
kwargs['max_retries'] = max_retries
498+
499+
if min_delay_between_retries is not None:
500+
kwargs['min_delay_between_retries_millis'] = int(min_delay_between_retries.total_seconds() * 1000)
501+
502+
if timeout is not None:
503+
kwargs['timeout_secs'] = int(timeout.total_seconds())
504+
505+
return ApifyClientAsync(**kwargs) # ty: ignore[invalid-argument-type]
502506

503507
async def open_dataset(
504508
self,

tests/integration/actor/conftest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@ async def _make_actor(
162162
if (main_func and main_py) or (main_func and source_files) or (main_py and source_files):
163163
raise TypeError('Cannot specify more than one of `main_func`, `main_py` and `source_files` arguments')
164164

165-
client = ApifyClientAsync(token=apify_token, api_url=os.getenv(_API_URL_ENV_VAR))
165+
api_url = os.getenv(_API_URL_ENV_VAR)
166+
client = (
167+
ApifyClientAsync(token=apify_token)
168+
if api_url is None
169+
else ApifyClientAsync(token=apify_token, api_url=api_url)
170+
)
171+
166172
actor_name = generate_unique_resource_name(label)
167173

168174
# Get the source of main_func and convert it into a reasonable main_py file.
@@ -256,7 +262,12 @@ async def _make_actor(
256262

257263
# Delete all the generated Actors.
258264
for actor_id in actors_for_cleanup:
259-
apify_client = ApifyClient(token=apify_token, api_url=os.getenv(_API_URL_ENV_VAR))
265+
api_url = os.getenv(_API_URL_ENV_VAR)
266+
267+
apify_client = (
268+
ApifyClient(token=apify_token) if api_url is None else ApifyClient(token=apify_token, api_url=api_url)
269+
)
270+
260271
actor_client = apify_client.actor(actor_id)
261272
actor = actor_client.get()
262273

tests/integration/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def apify_token() -> str:
3434
def apify_client_async(apify_token: str) -> ApifyClientAsync:
3535
"""Create an instance of the ApifyClientAsync."""
3636
api_url = os.getenv(_API_URL_ENV_VAR)
37-
38-
return ApifyClientAsync(apify_token, api_url=api_url)
37+
return ApifyClientAsync(apify_token) if api_url is None else ApifyClientAsync(apify_token, api_url=api_url)
3938

4039

4140
@pytest.fixture

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)