Skip to content

Commit 10fb739

Browse files
committed
refactor!: Introduce fully typed clients
1 parent 308ddf3 commit 10fb739

File tree

106 files changed

+14572
-4884
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+14572
-4884
lines changed

.github/workflows/_tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
operating_systems: '["ubuntu-latest", "windows-latest"]'
2121
python_version_for_codecov: "3.14"
2222
operating_system_for_codecov: ubuntu-latest
23-
tests_concurrency: "1"
23+
tests_concurrency: "16"
2424

2525
integration_tests:
2626
name: Integration tests
@@ -31,4 +31,4 @@ jobs:
3131
operating_systems: '["ubuntu-latest"]'
3232
python_version_for_codecov: "3.14"
3333
operating_system_for_codecov: ubuntu-latest
34-
tests_concurrency: "1"
34+
tests_concurrency: "16"

docs/01_overview/code/01_usage_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ async def main() -> None:
1616
return
1717

1818
# Fetch results from the Actor run's default dataset.
19-
dataset_client = apify_client.dataset(call_result['defaultDatasetId'])
19+
dataset_client = apify_client.dataset(call_result.default_dataset_id)
2020
list_items_result = await dataset_client.list_items()
2121
print(f'Dataset: {list_items_result}')

docs/01_overview/code/01_usage_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def main() -> None:
1616
return
1717

1818
# Fetch results from the Actor run's default dataset.
19-
dataset_client = apify_client.dataset(call_result['defaultDatasetId'])
19+
dataset_client = apify_client.dataset(call_result.default_dataset_id)
2020
list_items_result = dataset_client.list_items()
2121
print(f'Dataset: {list_items_result}')

docs/02_concepts/code/01_async_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async def main() -> None:
1111

1212
# Start the Actor and get the run ID
1313
run_result = await actor_client.start()
14-
run_client = apify_client.run(run_result['id'])
14+
run_client = apify_client.run(run_result.id)
1515
log_client = run_client.log()
1616

1717
# Stream the logs
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import timedelta
2+
13
from apify_client import ApifyClientAsync
24

35
TOKEN = 'MY-APIFY-TOKEN'
@@ -7,6 +9,6 @@ async def main() -> None:
79
apify_client = ApifyClientAsync(
810
token=TOKEN,
911
max_retries=8,
10-
min_delay_between_retries_millis=500, # 0.5s
11-
timeout_secs=360, # 6 mins
12+
min_delay_between_retries=timedelta(milliseconds=500), # 0.5s
13+
timeout=timedelta(seconds=360), # 6 mins
1214
)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import timedelta
2+
13
from apify_client import ApifyClient
24

35
TOKEN = 'MY-APIFY-TOKEN'
@@ -7,6 +9,6 @@ async def main() -> None:
79
apify_client = ApifyClient(
810
token=TOKEN,
911
max_retries=8,
10-
min_delay_between_retries_millis=500, # 0.5s
11-
timeout_secs=360, # 6 mins
12+
min_delay_between_retries=timedelta(milliseconds=500), # 0.5s
13+
timeout=timedelta(seconds=360), # 6 mins
1214
)

docs/03_examples/code/01_input_async.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
from datetime import timedelta
23

34
from apify_client import ApifyClientAsync
45

@@ -16,7 +17,9 @@ async def main() -> None:
1617

1718
# Run the Actor and wait for it to finish up to 60 seconds.
1819
# Input is not persisted for next runs.
19-
run_result = await actor_client.call(run_input=input_data, timeout_secs=60)
20+
run_result = await actor_client.call(
21+
run_input=input_data, timeout=timedelta(seconds=60)
22+
)
2023

2124

2225
if __name__ == '__main__':

docs/03_examples/code/01_input_sync.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import timedelta
2+
13
from apify_client import ApifyClient
24

35
TOKEN = 'MY-APIFY-TOKEN'
@@ -14,7 +16,7 @@ def main() -> None:
1416

1517
# Run the Actor and wait for it to finish up to 60 seconds.
1618
# Input is not persisted for next runs.
17-
run_result = actor_client.call(run_input=input_data, timeout_secs=60)
19+
run_result = actor_client.call(run_input=input_data, timeout=timedelta(seconds=60))
1820

1921

2022
if __name__ == '__main__':

docs/03_examples/code/02_tasks_async.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import asyncio
22

33
from apify_client import ApifyClientAsync
4-
from apify_client.clients.resource_clients import TaskClientAsync
4+
from apify_client._models import Run, Task
5+
from apify_client._resource_clients import TaskClientAsync
56

67
TOKEN = 'MY-APIFY-TOKEN'
78
HASHTAGS = ['zebra', 'lion', 'hippo']
89

910

10-
async def run_apify_task(client: TaskClientAsync) -> dict:
11-
result = await client.call()
12-
return result or {}
11+
async def run_apify_task(client: TaskClientAsync) -> Run | None:
12+
return await client.call()
1313

1414

1515
async def main() -> None:
1616
apify_client = ApifyClientAsync(token=TOKEN)
1717

1818
# Create Apify tasks
19-
apify_tasks = list[dict]()
19+
apify_tasks = list[Task]()
2020
apify_tasks_client = apify_client.tasks()
2121

2222
for hashtag in HASHTAGS:
@@ -34,7 +34,7 @@ async def main() -> None:
3434
apify_task_clients = list[TaskClientAsync]()
3535

3636
for apify_task in apify_tasks:
37-
task_id = apify_task['id']
37+
task_id = apify_task.id
3838
apify_task_client = apify_client.task(task_id)
3939
apify_task_clients.append(apify_task_client)
4040

docs/03_examples/code/02_tasks_sync.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
from apify_client import ApifyClient
2-
from apify_client.clients.resource_clients import TaskClient
2+
from apify_client._models import Run, Task
3+
from apify_client._resource_clients import TaskClient
34

45
TOKEN = 'MY-APIFY-TOKEN'
56
HASHTAGS = ['zebra', 'lion', 'hippo']
67

78

8-
def run_apify_task(client: TaskClient) -> dict:
9-
result = client.call()
10-
return result or {}
9+
def run_apify_task(client: TaskClient) -> Run | None:
10+
return client.call()
1111

1212

1313
def main() -> None:
1414
apify_client = ApifyClient(token=TOKEN)
1515

1616
# Create Apify tasks
17-
apify_tasks = list[dict]()
17+
apify_tasks = list[Task]()
1818
apify_tasks_client = apify_client.tasks()
1919

2020
for hashtag in HASHTAGS:
@@ -32,18 +32,19 @@ def main() -> None:
3232
apify_task_clients = list[TaskClient]()
3333

3434
for apify_task in apify_tasks:
35-
task_id = apify_task['id']
35+
task_id = apify_task.id
3636
apify_task_client = apify_client.task(task_id)
3737
apify_task_clients.append(apify_task_client)
3838

3939
print('Task clients created:', apify_task_clients)
4040

4141
# Execute Apify tasks
42-
task_run_results = list[dict]()
42+
task_run_results = list[Run]()
4343

4444
for client in apify_task_clients:
4545
result = run_apify_task(client)
46-
task_run_results.append(result)
46+
if result is not None:
47+
task_run_results.append(result)
4748

4849
print('Task results:', task_run_results)
4950

0 commit comments

Comments
 (0)