The official Python client for the Apify REST API.
apify-client lets you talk to the Apify platform from Python — run Actors, manage storages (datasets, key-value stores, request queues), schedule tasks, configure webhooks, and use everything else exposed by the Apify API. It ships both synchronous and asynchronous clients, fully typed responses, automatic retries with exponential backoff, tiered timeouts, pagination helpers, streaming, and a pluggable HTTP layer.
If you want to build Apify Actors in Python rather than consume the API, use the Apify SDK for Python instead — it bundles this client and adds Actor-side primitives.
- Installation
- Quick start
- Features
- Usage examples
- Documentation
- Related projects
- Support and community
- Contributing
- License
apify-client requires Python 3.11 or higher. It is published on PyPI and can be installed for example with pip:
pip install apify-clientor with uv:
uv add apify-clientor any other Python package manager that consumes PyPI.
You'll need an Apify API token — find yours in the Integrations section of Apify Console. Pass it to the client and you're ready to go.
from apify_client import ApifyClient
client = ApifyClient('MY-APIFY-TOKEN')
# Start an Actor and wait for it to finish.
run = client.actor('apify/hello-world').call(
run_input={'message': 'Hello, Apify!'},
)
# Iterate items from the run's default dataset.
for item in client.dataset(run.default_dataset_id).iterate_items():
print(item)import asyncio
from apify_client import ApifyClientAsync
async def main() -> None:
client = ApifyClientAsync('MY-APIFY-TOKEN')
run = await client.actor('apify/hello-world').call(
run_input={'message': 'Hello, Apify!'},
)
# Iterate items from the run's default dataset.
async for item in client.dataset(run.default_dataset_id).iterate_items():
print(item)
asyncio.run(main())Keep your token secret. It authorizes requests on your behalf and can incur usage costs. Never commit it to source control or expose it to client-side code.
For a guided walkthrough — authenticating, running an Actor, and reading its results — see the Quick start guide.
- Synchronous and asynchronous clients — pick
ApifyClientorApifyClientAsyncto match your codebase; both expose the same API (Asyncio support). - Fully typed responses — every method returns a Pydantic model generated from the Apify OpenAPI spec, with IDE autocomplete and runtime validation (Typed models).
- Automatic retries — exponential backoff for network errors, HTTP 429, and 5xx responses, configurable per client (Retries).
- Tiered timeouts — short / medium / long tiers picked per endpoint, overridable per call (Timeouts).
- Pagination and streaming — iterate datasets, key-value store keys, or live logs without manual paging or buffering (Pagination, Streaming).
- Convenience methods —
call(),wait_for_finish(), nested resource access, and other shortcuts that hide platform quirks (Convenience methods). - Pluggable HTTP layer — swap the default Impit-based HTTP client for
httpx,requests,aiohttp, or any custom implementation (Custom HTTP clients). - Structured errors — every API error surfaces as an
ApifyApiErrorwith HTTP-specific subclasses for precise handling (Error handling). - Debug logging — opt-in structured logging on the
apify_clientlogger captures request URLs, status codes, retry attempts, and more (Logging).
The client mirrors the platform's resource model. Each entry point returns either a single-resource client for an individual item or a collection client for listing and creating items (Single and collection clients).
actors = client.actors()
print(actors.list(limit=10).items)
new_actor = actors.create(name='my-actor')run = client.actor('apify/web-scraper').start(run_input={...})
with client.run(run.id).log().stream() as log_stream:
for chunk in log_stream.iter_bytes():
print(chunk.decode(), end='')store = client.key_value_store('STORE-ID')
store.set_record('greeting', {'message': 'Hello!'})
record = store.get_record('greeting')for item in client.dataset('DATASET-ID').iterate_items(fields='title,url'):
process(item)from datetime import timedelta
from apify_client import ApifyClient
client = ApifyClient(
token='MY-APIFY-TOKEN',
max_retries=8,
min_delay_between_retries=timedelta(milliseconds=500),
timeout_long=timedelta(minutes=10),
)For end-to-end recipes — passing input, managing tasks for reusable input, retrieving and merging Actor data, integrating with Pandas, plugging in a custom HTTP client — see the Guides.
The full documentation lives at docs.apify.com/api/client/python.
| Section | What you'll find |
|---|---|
| Introduction | Overview, prerequisites, and a tour of the client. |
| Quick start | Authenticate, run an Actor, and fetch its results step by step. |
| Concepts | Asyncio, single vs. collection clients, nested clients, error handling, retries, logging, convenience methods, pagination, streaming, custom HTTP clients, timeouts. |
| Guides | Pass input to an Actor, manage tasks for reusable input, retrieve Actor data, integrate with data libraries (e.g. Pandas), use HTTPX as the HTTP client. |
| Upgrading | Migrating between major versions. |
| API reference | Generated reference for every class, method, and model. |
| Changelog | Release history and breaking changes. |
- Apify SDK for Python — toolkit for building Apify Actors in Python (this client is bundled with it).
- Crawlee for Python — high-level web scraping and browser automation framework that powers many Actors.
- Apify API client for JavaScript / TypeScript — equivalent Apify API client for Node.js.
- Apify SDK for JavaScript / TypeScript — equivalent Apify SDK for Node.js.
- Crawlee for JavaScript / TypeScript — original Node.js implementation of the Crawlee framework.
- Apify CLI — command-line tool for interacting with the Apify platform: managing Actors, runs, storages, local development, and deployment.
- Discord — chat with the team and other users on the Apify Discord server.
- GitHub issues — report a bug or request a feature in the repository's issue tracker.
Bug reports, fixes, and improvements are welcome! See CONTRIBUTING.md for the development setup, coding standards, testing, and the release process. The repo uses uv for project management and Poe the Poet as a task runner; the typical loop is:
uv run poe install-dev # install dev deps and git hooks
uv run poe check-code # lint, type-check, unit tests, docstring checkReleased under the Apache License 2.0.