# Overview
Copy for LLM
The Apify SDK for Python is the official library for creating [Apify Actors](https://docs.apify.com/platform/actors) in Python.
```
from apify import Actor
from bs4 import BeautifulSoup
import requests
async def main():
async with Actor:
input = await Actor.get_input()
response = requests.get(input['url'])
soup = BeautifulSoup(response.content, 'html.parser')
await Actor.push_data({ 'url': input['url'], 'title': soup.title.string })
```
## Requirements[](#requirements)
The Apify SDK requires Python version 3.10 or above to run Python Actors locally.
## Installation[](#installation)
The Apify Python SDK is available as [`apify`](https://pypi.org/project/apify/) package on PyPi. To install it, run:
```
pip install apify
```
When you create an Actor using the Apify CLI, the Apify SDK for Python is installed for you automatically.
If you are not developing Apify Actors and you just need to access the Apify API from Python, consider using the [Apify API client for Python](https://docs.apify.com/sdk/python/api/client/python) directly.
## Quick start[](#quick-start)
### Creating Actors[](#creating-actors)
To create and run Actors in Apify Console, refer to the [Console documentation](https://docs.apify.com/sdk/python/sdk/python/platform/actors/development/quick-start/web-ide).
To create a new Apify Actor on your computer, you can use the [Apify CLI](https://docs.apify.com/sdk/python/cli), and select one of the [Python Actor templates](https://apify.com/templates?category=python).
For example, to create an Actor from the "\[beta] Python SDK" template, you can use the [`apify create` command](https://docs.apify.com/sdk/python/cli/docs/reference#apify-create-actorname).
```
apify create my-first-actor --template python-start
```
This will create a new folder called `my-first-actor`, download and extract the "Getting started with Python" Actor template there, create a virtual environment in `my-first-actor/.venv`, and install the Actor dependencies in it.

#### Running the Actor[](#running-the-actor)
To run the Actor, you can use the [`apify run` command](https://docs.apify.com/sdk/python/cli/docs/reference#apify-run):
```
cd my-first-actor
apify run
```
This command:
* Activates the virtual environment in `.venv` (if no other virtual environment is activated yet)
* Starts the Actor with the appropriate environment variables for local running
* Configures it to use local storages from the `storage` folder
The Actor input, for example, will be in `storage/key_value_stores/default/INPUT.json`.
## Actor structure[](#actor-structure)
All Python Actor templates follow the same structure.
The `.actor` directory contains the [Actor configuration](https://docs.apify.com/sdk/python/sdk/python/platform/actors/development/actor-config), such as the Actor's definition and input schema, and the Dockerfile necessary to run the Actor on the Apify platform.
The Actor's runtime dependencies are specified in the `requirements.txt` file, which follows the [standard requirements file format](https://pip.pypa.io/en/stable/reference/requirements-file-format/).
The Actor's source code is in the `src` folder. This folder contains two important files:
* `main.py` - which contains the main function of the Actor
* `__main__.py` - which is the entrypoint of the Actor package setting up the Actor [logger](https://docs.apify.com/sdk/python/sdk/python/concepts/logging) and executing the Actor's main function via [`asyncio.run()`](https://docs.python.org/3/library/asyncio-runner.html#asyncio.run).
- main.py
- \_\_main.py\_\_
```
from apify import Actor
async def main():
async with Actor:
Actor.log.info('Actor input:', await Actor.get_input())
await Actor.set_value('OUTPUT', 'Hello, world!')
```
```
import asyncio
import logging
from apify.log import ActorLogFormatter
from .main import main
handler = logging.StreamHandler()
handler.setFormatter(ActorLogFormatter())
apify_logger = logging.getLogger('apify')
apify_logger.setLevel(logging.DEBUG)
apify_logger.addHandler(handler)
asyncio.run(main())
```
If you want to modify the Actor structure, you need to make sure that your Actor is executable as a module, via `python -m src`, as that is the command started by `apify run` in the Apify CLI. We recommend keeping the entrypoint for the Actor in the `src/__main__.py` file.
## Adding dependencies[](#adding-dependencies)
First, add the dependencies in the [`requirements.txt`](https://pip.pypa.io/en/stable/reference/requirements-file-format/) file in the Actor source folder.
Then activate the virtual environment in `.venv`:
* Linux / macOS
* Windows
```
source .venv/bin/activate
```
```
.venv\Scripts\activate
```
Finally, install the dependencies:
```
python -m pip install -r requirements.txt
```
## Next steps[](#next-steps)
### Guides[](#guides)
To see how you can integrate the Apify SDK with some of the most popular web scraping libraries, check out our guides for working with:
* [Requests or HTTPX](https://docs.apify.com/sdk/python/sdk/python/guides/requests-and-httpx)
* [Beautiful Soup](https://docs.apify.com/sdk/python/sdk/python/guides/beautiful-soup)
* [Playwright](https://docs.apify.com/sdk/python/sdk/python/guides/playwright)
* [Selenium](https://docs.apify.com/sdk/python/sdk/python/guides/selenium)
* [Scrapy](https://docs.apify.com/sdk/python/sdk/python/guides/scrapy)
### Usage concepts[](#usage-concepts)
To learn more about the features of the Apify SDK and how to use them, check out the Usage Concepts section in the sidebar, especially the guides for:
* [Actor lifecycle](https://docs.apify.com/sdk/python/sdk/python/concepts/actor-lifecycle)
* [Working with storages](https://docs.apify.com/sdk/python/sdk/python/concepts/storages)
* [Handling Actor events](https://docs.apify.com/sdk/python/sdk/python/concepts/actor-events)
* [How to use proxies](https://docs.apify.com/sdk/python/sdk/python/concepts/proxy-management)