Running Python Actors locally
Requirements
The Apify SDK requires Python version 3.8 or above to run Python actors locally.
Creating your first Actor
To create a new Apify Actor on your computer, you can use the Apify CLI, and select one of the Python Actor templates.
For example, to create an Actor from the "[beta] Python SDK" template,
you can use the apify create
command.
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
To run the Actor, you can use the apify run
command:
cd my-first-actor
apify run
This will activate the virtual environment in .venv
(if no other virtual environment is activated yet),
then start the Actor, passing the right environment variables for local running,
and configure it to use local storages from the storage
folder.
The Actor input, for example, will be in storage/key_value_stores/default/INPUT.json
.
Adding dependencies
Adding dependencies into the Actor is simple.
First, add them in the requirements.txt
file in the Actor source folder.
Then activate the virtual environment in .venv
:
- Linux / macOS
- Windows
source .venv/bin/activate
.venv\Scripts\activate
Then install the dependencies:
python -m pip install -r requirements.txt