| id | introduction |
|---|---|
| title | Overview |
| slug | /overview |
| description | The official library for creating Apify Actors in Python, providing tools for web scraping, automation, and data storage integration. |
import CodeBlock from '@theme/CodeBlock';
import IntroductionExample from '!!raw-loader!./code/01_introduction.py';
The Apify SDK for Python is the official library for creating Apify Actors in Python. It provides everything you need to build an Actor and run it both locally and on the Apify platform. It handles the Actor lifecycle, storage access, platform events, Apify Proxy, pay-per-event charging, and more.
{IntroductionExample}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.
- Run the full Actor lifecycle inside
async with Actor:, covering init, exit, failures, status messages, rebooting, and metamorphing (Actor lifecycle). - Read Actor input validated against your input schema with
Actor.get_input(), including automatic decryption of secret fields (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, and persist state across migrations and restarts (Actor events).
- Route requests through Apify Proxy with group selection, country targeting, and rotation, with session and tiered-proxy support (Proxy management).
- Start, call, and abort 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).
Almost any Python project can become an Actor, including projects for:
- Web scraping and crawling - The SDK is fully compatible with Crawlee, which makes Apify a natural place to deploy and scale your crawlers (see the Crawlee guide). It also works with other popular scraping libraries, such as Scrapy, Scrapling, or Crawl4AI.
- Browser automation - Drive a real browser with Playwright or Selenium, or with higher-level tools such as Browser Use.
- Web servers and APIs - Run a web server inside an Actor to serve HTTP requests, for example to expose your scraper as a live API.
- AI agents - Host agents built with your framework of choice (see the AI agents guide). Ready-made Actor templates cover PydanticAI, CrewAI, LangGraph, LlamaIndex, and Smolagents.
- MCP servers - Deploy a Python MCP server as an Actor and make its tools available to any MCP client. See the MCP server and MCP proxy templates.
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.
To create and run Actors using Apify Console, check out Apify Console documentation. For creating and running Python Actors locally, refer to the quick start guide.
Explore the Guides section in the sidebar for a deeper understanding of the SDK's features and best practices.
The Apify SDK for Python requires Python version 3.11 or above. It is typically installed when you create a new Actor project using the Apify CLI. To install it manually in an existing project, use:
pip install apify:::note API client alternative
If you need to interact with the Apify API programmatically without creating Actors, use the Apify API client for Python instead.
:::