{"id":3400,"library":"apify-client","title":"Apify Client","description":"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.","status":"active","version":"2.5.0","language":"en","source_language":"en","source_url":"https://github.com/apify/apify-client-python","tags":["apify","web scraping","api client","automation","crawler"],"install":[{"cmd":"pip install apify-client","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for underlying HTTP requests, supporting both synchronous and asynchronous operations.","package":"httpx","optional":false}],"imports":[{"symbol":"ApifyClient","correct":"from apify_client import ApifyClient"}],"quickstart":{"code":"import os\nfrom apify_client import ApifyClient\n\n# Initialize the ApifyClient with your Apify API token.\n# It's recommended to store your token in an environment variable named APIFY_TOKEN.\n# Alternatively, pass it directly: apify_client = ApifyClient(token='YOUR_APIFY_TOKEN')\napify_client = ApifyClient(token=os.environ.get('APIFY_TOKEN', ''))\n\n# Ensure an API token is provided\nif not apify_client.token:\n    print(\"Warning: APIFY_TOKEN not found. Most operations will fail without authentication.\")\n    # In a real application, you might raise an error or exit here.\n    # For this quickstart, we'll continue but expect failures for authenticated calls.\n\n# Run a specific Actor (replace 'apify/hello-world' with your Actor ID)\ntry:\n    actor_run = apify_client.actor('apify/hello-world').call()\n\n    # Fetch results from the Actor's default dataset\n    print(f'Actor run data from dataset: {apify_client.dataset(actor_run[\"defaultDatasetId\"]).list_items().items}')\n\n    # Or to fetch items one by one:\n    # for item in apify_client.dataset(actor_run[\"defaultDatasetId\"]).iterate_items():\n    #     print(item)\nexcept Exception as e:\n    print(f\"An error occurred while running the Actor or fetching data: {e}\")\n    print(\"Please ensure your APIFY_TOKEN is valid and the 'apify/hello-world' actor is accessible.\")","lang":"python","description":"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."},"warnings":[{"fix":"Replace `ApifyClientSync(token='...')` or `ApifyClientAsync(token='...')` with `ApifyClient(token='...')`.","message":"Breaking 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.","severity":"breaking","affected_versions":"1.x to 2.x"},{"fix":"Update resource access calls. For example, `client.actors().get('id')` becomes `client.actor('id').get()`.","message":"Breaking 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`.","severity":"breaking","affected_versions":"1.x to 2.x"},{"fix":"Set the `APIFY_TOKEN` environment variable or pass `token='YOUR_APIFY_TOKEN'` directly to `ApifyClient()`.","message":"API 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).","severity":"gotcha","affected_versions":"All"},{"fix":"Use `list_items()` with `limit` and `offset` parameters or, preferably, `iterate_items()` for efficient, paginated access to large datasets.","message":"Pagination 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}