Skip to content

Commit 06f4699

Browse files
vdusekclaude
andcommitted
docs: Add usage examples to ApifyClient and ApifyClientAsync docstrings
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fcfea6c commit 06f4699

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/apify_client/_apify_client.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ class ApifyClient:
8989
schedules, webhooks, and more.
9090
9191
The client automatically handles retries with exponential backoff for failed or rate-limited requests.
92+
93+
### Usage
94+
95+
```python
96+
from apify_client import ApifyClient
97+
98+
client = ApifyClient(token='MY-APIFY-TOKEN')
99+
100+
# Start an Actor and wait for it to finish.
101+
actor_client = client.actor('username/my-actor')
102+
run = actor_client.call(run_input={'query': 'web scraping'})
103+
104+
# Fetch results from the run's default dataset.
105+
dataset_client = client.dataset(run['defaultDatasetId'])
106+
items = dataset_client.list_items().items
107+
for item in items:
108+
print(item)
109+
```
92110
"""
93111

94112
_OVERRIDABLE_DEFAULT_HEADERS: ClassVar[set[str]] = {'Accept', 'Authorization', 'Accept-Encoding', 'User-Agent'}
@@ -359,6 +377,29 @@ class ApifyClientAsync:
359377
request queues, schedules, webhooks, and more.
360378
361379
The client automatically handles retries with exponential backoff for failed or rate-limited requests.
380+
381+
### Usage
382+
383+
```python
384+
import asyncio
385+
386+
from apify_client import ApifyClientAsync
387+
388+
async def main() -> None:
389+
client = ApifyClientAsync(token='MY-APIFY-TOKEN')
390+
391+
# Start an Actor and wait for it to finish.
392+
actor_client = client.actor('username/my-actor')
393+
run = await actor_client.call(run_input={'query': 'web scraping'})
394+
395+
# Fetch results from the run's default dataset.
396+
dataset_client = client.dataset(run['defaultDatasetId'])
397+
items = (await dataset_client.list_items()).items
398+
for item in items:
399+
print(item)
400+
401+
asyncio.run(main())
402+
```
362403
"""
363404

364405
_OVERRIDABLE_DEFAULT_HEADERS: ClassVar[set[str]] = {'Accept', 'Authorization', 'Accept-Encoding', 'User-Agent'}

0 commit comments

Comments
 (0)