Introduction
The Apify SDK for Python is the official library for creating Apify Actors using Python.
import httpx
from bs4 import BeautifulSoup
from apify import Actor
async def main() -> None:
async with Actor:
actor_input = await Actor.get_input()
async with httpx.AsyncClient() as client:
response = await client.get(actor_input['url'])
soup = BeautifulSoup(response.content, 'html.parser')
data = {
'url': actor_input['url'],
'title': soup.title.string if soup.title else None,
}
await Actor.push_data(data)
What are Actors?
Actors are serverless cloud programs capable of performing tasks in a web browser, similar to what a human can do. These tasks can range from simple operations, such as filling out forms or unsubscribing from services, to complex jobs like scraping and processing large numbers of web pages.
Actors can be executed locally or on the Apify platform, which provides features for running them at scale, monitoring, scheduling, and even publishing and monetizing them.
If you're new to Apify, refer to the Apify platform documentation to learn what Apify is.
Quick start
This section provides a quick start guide for creating and running Actors.
Creating Actors
To create and run Actors using the Apify Console, see the Console documentation.
For creating and running Python Actors locally, refer to the documentation for creating and running Python Actors locally.
Guides
Integrate the Apify SDK with popular web scraping libraries by following these guides:
Usage concepts
For a deeper understanding of the Apify SDK's features, refer to the Usage concepts section in the sidebar. Key topics include:
Installing the Apify SDK separately
When creating an Actor using the Apify CLI, the Apify SDK for Python is installed automatically. If you want to install it independently, use the following command:
pip install apify
If your goal is not to develop Apify Actors but to interact with the Apify API from Python, consider using the Apify API client for Python directly.