Registry / http-networking / apify-client

apify-client

JSON →
library3.1.3pypypi✓ verified 23d ago

The Apify Client for Python allows users to interact with the Apify platform, managing actors, datasets, key-value stores, and more. It provides both synchronous and asynchronous interfaces for web scraping and automation tasks. The current stable version is 2.5.0, with regular updates.

pip install apify-client
INSTALL
IMPORT
SIG · APIFY-CLIENT
A
apify-client
http-networkingpythonv3.1.3
Install
3.1s avg
Import
1464ms
Disk
35MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.450s · 29MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.1s · import 1.478s · 29MB
35MB installed
● package 35MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ApifyClient
from apify_client import ApifyClient

This quickstart demonstrates how to initialize the Apify client, run a 'Hello World' actor, and retrieve its results from the default dataset. It emphasizes secure API token handling via environment variables.

import os from apify_client import ApifyClient # Initialize the ApifyClient with your Apify API token. # It's recommended to store your token in an environment variable named APIFY_TOKEN. # Alternatively, pass it directly: apify_client = ApifyClient(token='YOUR_APIFY_TOKEN') apify_client = ApifyClient(token=os.environ.get('APIFY_TOKEN', '')) # Ensure an API token is provided if not apify_client.token: print("Warning: APIFY_TOKEN not found. Most operations will fail without authentication.") # In a real application, you might raise an error or exit here. # For this quickstart, we'll continue but expect failures for authenticated calls. # Run a specific Actor (replace 'apify/hello-world' with your Actor ID) try: actor_run = apify_client.actor('apify/hello-world').call() # Fetch results from the Actor's default dataset print(f'Actor run data from dataset: {apify_client.dataset(actor_run["defaultDatasetId"]).list_items().items}') # Or to fetch items one by one: # for item in apify_client.dataset(actor_run["defaultDatasetId"]).iterate_items(): # print(item) except Exception as e: print(f"An error occurred while running the Actor or fetching data: {e}") print("Please ensure your APIFY_TOKEN is valid and the 'apify/hello-world' actor is accessible.")
Debug
Known issues
breakingBreaking Change: V1 to V2 API Client Initialization. In `v2.x`, the `ApifyClient` constructor directly accepts `token='YOUR_TOKEN'`, unifying the previous `ApifyClientSync` and `ApifyClientAsync` classes from `v1.x`. Users migrating from `v1.x` must adapt to this single client and direct token parameter.
fix
Replace `ApifyClientSync(token='...')` or `ApifyClientAsync(token='...')` with `ApifyClient(token='...')`.
affects: 1.x to 2.x
breakingBreaking Change: V1 to V2 Resource Access Patterns. Accessing Apify resources (Actors, Datasets, Key-Value Stores, etc.) moved from methods like `client.actors().get_or_create(...)` in `v1.x` to a more direct chainable pattern like `client.actor(...).get_or_create()` in `v2.x`.
fix
Update resource access calls. For example, `client.actors().get('id')` becomes `client.actor('id').get()`.
affects: 1.x to 2.x
gotchaAPI Token Requirement: Most Apify API operations require an API token for authentication. If the `APIFY_TOKEN` environment variable is not set or the `token` parameter is not explicitly passed to the `ApifyClient` constructor, operations will typically result in authentication errors (e.g., 401 Unauthorized).
fix
Set the `APIFY_TOKEN` environment variable or pass `token='YOUR_APIFY_TOKEN'` directly to `ApifyClient()`.
affects: All
gotchaPagination for Large Datasets: When retrieving a large number of items from datasets or key-value stores, fetching all items at once can lead to memory exhaustion. Always use iterative methods or pagination parameters.
fix
Use `list_items()` with `limit` and `offset` parameters or, preferably, `iterate_items()` for efficient, paginated access to large datasets.
affects: All
Errors
Common errors & fixes
TypeError: 'NoneType' object is not callable
This error occurs when importing 'apify_client' inside a Docker container due to compatibility issues with Python versions.
fix
Ensure that the Docker container is using Python 3.10 or higher, as 'apify-client' requires Python 3.10 or higher. ([docs.apify.com](https://docs.apify.com/api/client/python/?utm_source=openai))
ApifyApiError: Actor 'non-existent-actor' does not exist
This error occurs when attempting to access an Actor that does not exist on the Apify platform.
fix
Verify that the Actor ID is correct and that the Actor exists on the Apify platform. ([docs.apify.com](https://docs.apify.com/api/client/python/docs/concepts/error-handling?utm_source=openai))
ApifyApiError: Request failed with status code 429
This error occurs when the Apify API rate limit is exceeded.
fix
Implement exponential backoff and retry logic to handle rate limit errors. ([docs.apify.com](https://docs.apify.com/api/client/python/docs/concepts/retries?utm_source=openai))
ModuleNotFoundError: No module named 'apify-client'
The 'apify-client' library is not installed in your Python environment.
fix
Run `pip install apify-client` in your terminal to install the library.
ApifyApiError: Authentication token was not provided.
The Apify client was initialized without an API token, or the token provided is invalid or expired, which is required for most API operations.
fix
Initialize the ApifyClient with a valid API token: `apify_client = ApifyClient('YOUR_API_TOKEN')`. You can find your API token in the Apify Console under 'Integrations'.
Upgrade
Version history
3.1.3latest on PyPI · released Aug 18, 2026
Audit
Dependencies
httpxrequiredUsed for underlying HTTP requests, supporting both synchronous and asynchronous operations.
Agent activity
32 hits · last 30 days
node
28
OpenAI (training)
1
Resources
apify-client — pip install apify-client · libregistry