Discover / Data & Research

Apify SDK for Python

by apifyPython

Python SDK for building scalable web scraping and automation actors on the Apify platform.

Repositorystable

Maturity: stable because 4y old, v4.0.0 released 14d ago. Derived from release and commit history, not a rating.

Stars
174
Forks
27
Downloads / mo
257k
Last commit
2026-07-31
License
Apache-2.0
Open issues
12

Market and trust evidence

Edition not yet matched

No exact skills.sh identity match is available for this repository. Repository adoption and freshness remain visible above; install momentum is not inferred.

Trust analysis is a screening signal, not a security warranty. Read the ranking and trust methodology.

In practice

Written by AI from this repository’s README · high confidence

A developer writing a scraper or automation has to hand roll input handling, storage, events and proxy rotation.

Use it when

Use it when you are building an Actor that will run on the Apify platform or locally with the same storage and lifecycle API.

Not the right pick when

If you only need to call the Apify API rather than build Actors, the README says to use the Apify API client instead.

Capabilities

  • full Actor lifecycle inside async with Actor
  • input validated against an input schema
  • datasets, key-value stores and request queues
  • platform events such as migration and abort
  • Apify Proxy with group, country and rotation control
  • start, call, abort and metamorph other Actors

Requirements

  • Python 3.11 or higher
  • Apify CLI via npm for scaffolding a project

Cost: Open source with a paid cloud option

Install

Derived from the published package name in the repository, not from a model.

Video walkthroughs

Third-party YouTube uploads matched to this tool by title, channel and repository name on 2026-08-03. Not made, reviewed or endorsed by SkillPilot. View counts and publish months are as of the match date and the month is approximate. Nothing loads from YouTube until you press play.

What the repository ships

Ships CLAUDE.mdHas testsHas docsCI configured

Detected from the actual files in the repository root.

Latest release v4.0.0

Published 2026-07-20

4.0.0 (2026-07-20)

🚀 Features

  • Expose missing platform env vars via Actor.get_env() (#984) (f6e9b3b) by @vdusek
  • Re-export apify-client errors from apify.errors (#990) (165a3f6) by @vdusek

🐛 Bug Fixes

  • scrapy: Correct proxy middleware exception log and import (#953) (5bd6eb9) by @vdusek
  • scrapy: Skip a request that fails to convert instead of crashing the run (#952) (db9444f) by @vdusek
  • scrapy: [breaking] Serialize requests and HTTP cache as JSON instead of pickle (#951) (a87e8d1) by @vdusek
  • scrapy: Make logging configuration idempotent (#954) (2cc5602) by @vdusek
  • Bump typing-extensions floor to 4.4.0 (#960) (b7e7d9c) by @vdusek
  • Preserve decorated symbol types in docs_group and docs_name (#964) (6c359a7) by @vdusek
  • Exit already-entered contexts when Actor or event manager init fails (#969) (c1a15a7) by @vdusek
  • scrapy: Dump pydantic models in JSON mode when serializing requests (#961) (f2ccae1) by @vdusek
  • Accept arbitrary JSON userData in ApifyRequestList (#966) (2cfd8a5) by @vdusek
  • Coerce null stats in Apify request queue metadata (#974) (63eb771) by @vdusek
  • Allow Actor.reboot() to be retried after a failed or cancelled attempt (#968) (7d46ec5) by @vdusek
  • Correct reclaim_request count adjustment for already-handled requests (#973) (86f4cd5) by @vdusek
  • scrapy: Drop deprecated spider arg from Scrapy proxy middleware methods (#977) (49dd836) by @vdusek
  • Redirect input key in all file-system key-value store operations (#976) (1fbdce2) by @vdusek
  • Respect explicit zero custom_after_sleep in

Tags

README

<h1 align="center">Apify SDK for Python</h1>

<p align="center">

<strong>The official Python SDK for building <a href="https://docs.apify.com/platform/actors">Apify Actors</a>.</strong>

</p>

<p align="center">

<a href="https://pypi.org/project/apify/"><img src="https://badge.fury.io/py/apify.svg" alt="PyPI version"></a>

<a href="https://pypi.org/project/apify/"><img src="https://img.shields.io/pypi/dm/apify" alt="PyPI downloads"></a>

<a href="https://pypi.org/project/apify/"><img src="https://img.shields.io/badge/python-3.11%2B-blue" alt="Python versions"></a>

<a href="https://github.com/apify/apify-sdk-python/actions/workflows/on_master.yaml"><img src="https://github.com/apify/apify-sdk-python/actions/workflows/on_master.yaml/badge.svg?branch=master" alt="Build status"></a>

<a href="https://codecov.io/gh/apify/apify-sdk-python"><img src="https://codecov.io/gh/apify/apify-sdk-python/graph/badge.svg?token=Y6JBIZQFT6" alt="Coverage"></a>

<a href="https://github.com/apify/apify-sdk-python/blob/master/LICENSE"><img src="https://img.shields.io/pypi/l/apify" alt="License"></a>

<a href="https://discord.gg/jyEM2PRvMU"><img src="https://img.shields.io/discord/801163717915574323?label=discord" alt="Chat on Discord"></a>

</p>

apify is the official SDK for building Apify Actors in Python. It handles the Actor lifecycle, storage access, platform events, Apify Proxy, pay-per-event charging, and more.

If you only need to consume the Apify API from Python (running Actors, reading datasets, managing storages) rather than building Actors, use the Apify API client for Python instead. It comes bundled with this SDK.

Table of contents

  • Installation
  • Quick start
  • What are Actors?
  • Features
  • What you can build
  • Usage examples
  • Documentation
  • Related projects
  • Support and community
  • Contributing
  • License

Installation

The Apify SDK for Python requires Python 3.11 or higher. It is published on PyPI as the apify package and can be installed with pip:


pip install apify

or with uv:


uv add apify

To use the Scrapy integration, install the scrapy extra:


pip install 'apify[scrapy]'

Quick start

An Actor is a Python program that runs inside the async with Actor: context. The context initializes the Actor when it starts and tears it down when it finishes. Here's a minimal Actor that reads its input and stores a result:


from apify import Actor


async def main() -> None:
    async with Actor:
        actor_input = await Actor.get_input()
        Actor.log.info('Actor input: %s', actor_input)
        await Actor.set_value('OUTPUT', 'Hello, world!')

The quickest way to scaffold a full Actor project, with the .actor configuration, input schema, and Dockerfile already in place, is the Apify CLI:

  1. Install the CLI:

    npm install -g apify-cli
  1. Create a new Actor from the Python "getting started" template:

    apify create my-actor --template python-start
  1. Run it locally:

    cd my-actor
    apify run

To create, run, and deploy your first Actor step by step, see the Quick start guide.

What are Actors?

Actors are serverless programs that can do almost anything. From simple scripts and web scrapers to complex automation workflows, AI agents, or even always-on services that expose HTTP endpoints.

They can run either locally or on the Apify platform, where you can scale their execution, monitor runs, schedule tasks, integrate them with other services, or even publish and monetize them. If you're new to Apify, learn more about the platform in the Apify documentation.

For more context, read the Actor whitepaper.

Features

  • Run the full Actor lifecycle inside async with Actor:, covering init, exit, failures, status messages, and reboots (Actor lifecycle).
  • Read Actor input validated against your input schema with Actor.get_input() (Actor input).
  • Read and write datasets, key-value stores, and request queues, locally or on the platform (Working with storages).
  • React to platform events such as system info, migration, and abort (Actor events).
  • Route requests through Apify Proxy with group selection, country targeting, and rotation (Proxy management).
  • Start, call, abort, and metamorph other Actors and tasks, and attach webhooks to run events (Interacting with other Actors, Webhooks).
  • Monetize your Actor with pay-per-event charging (Pay-per-event).
  • Reach the full Apify API through a preconfigured ApifyClient (Accessing the Apify API).

What you can build

Almost any Python project can become an Actor, including projects for:

Whatever you build, the Apify SDK doesn't lock you into a particular framework. Bring the libraries you already use, and let Apify run your project in the cloud.

Usage examples

The examples below show two common setups, but the same async with Actor: pattern works with any stack. For more, see the guides.

HTTPX with BeautifulSoup

Scrape pages with HTTPX and BeautifulSoup, using the Actor's request queue to track URLs:


from bs4 import BeautifulSoup
from httpx import AsyncClient

from apify import Actor


async def main() -> None:
    async with Actor:
        actor_input = await Actor.get_input() or {}
        start_urls = actor_input.get('start_urls', [{'url': 'https://apify.com'}])

        # Enqueue the start URLs into the default request queue.
        request_queue = await Actor.open_request_queue()
        for start_url in start_urls:
            await request_queue.add_request(start_url['url'])

        # Process the queue until it's empty.
        while request := await request_queue.fetch_next_request():
            Actor.log.info(f'Scraping {request.url} ...')
            async with AsyncClient() as client:
                response = await client.get(request.url)
            soup = BeautifulSoup(response.content, 'html.parser')

            # Push the extracted data to the default dataset.
            await Actor.push_data(
                {
                    'url': request.url,
                    'title': soup.title.string if soup.title else None,
                }
            )

            # Mark the request as handled so it is not processed again.
            await request_queue.mark_request_as_handled(request)

Crawlee with Playwright

Scrape pages with Crawlee's PlaywrightCrawler, which handles queueing, concurrency, and the browser for you:


from crawlee.crawlers import PlaywrightCrawler, PlaywrightCrawlingContext

from apify import Actor


async def main() -> None:
    async with Actor:
        actor_input = await Actor.get_input() or {}
        start_urls = [url['url'] for url in actor_input.get('start_urls', [{'url': 'https://apify.com'}])]

        crawler = PlaywrightCrawler(max_requests_per_crawl=50, headless=True)

        @crawler.router.default_handler
        async def handler(context: PlaywrightCrawlingContext) -> None:
            Actor.log.info(f'Scraping {context.request.url} ...')
            await context.push_data(
                {
                    'url': context.request.url,
                    'title': await context.page.title(),
                }
            )
            # Follow links found on the page.
            await context.enqueue_links()

        await crawler.run(start_urls)

Documentation

The full SDK documentation lives at docs.apify.com/sdk/python. For the Apify platform itself, see the Apify documentation.

| Section | What you'll find |

| --- | --- |

| Overview | What the SDK is, what Actors are, and how the pieces fit together. |

| Quick start | Create, run, and deploy your first Python Actor. |

| Concepts | Actor lifecycle, input, storages, events, proxy management, interacting with other Actors, webhooks, accessing the Apify API, logging, configuration, and pay-per-event. |

| Guides | Integrations with BeautifulSoup, Parsel, Playwright, Selenium, Crawlee, Scrapy, Scrapling, Crawl4AI, and Browser Use, plus using uv, validating input with Pydantic, running a web server, building MCP servers, and hosting AI agents. |

| Upgrading | Migrating between major versions. |

| API reference | Generated reference for every class and method. |

| Changelog | Release history and breaking changes. |

Related projects

Support and community

Contributing

Bug reports, fixes, and improvements are welcome! See CONTRIBUTING.md for the development setup, coding standards, testing, and release process. The project uses uv for project management and Poe the Poet as a task runner; the typical loop is:


uv run poe install-dev   # install dev dependencies and git hooks
uv run poe check-code    # lint, type-check, and unit tests

License

Released under the Apache License 2.0.

Related tools