You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actors are serverless cloud programs that can do almost anything a human can do in a web browser.
28
-
They can do anything from small tasks such as filling in forms or unsubscribing from online services,
29
-
all the way up to scraping and processing vast numbers of web pages.
30
-
31
-
Actors can be run either locally, or on the [Apify platform](https://docs.apify.com/platform/),
32
-
where you can run them at scale, monitor them, schedule them, and even publish and monetize them.
33
-
34
-
If you're new to Apify, learn [what is Apify](https://docs.apify.com/platform/about) in the Apify platform documentation.
35
-
36
25
## Requirements
37
26
38
-
The Apify SDK requires Python version 3.8 or above to run Python actors locally.
27
+
The Apify SDK requires Python version 3.8 or above to run Python Actors locally.
39
28
40
29
## Installation
41
30
42
-
When you create an Actor using the Apify CLI, the Apify SDK for Python is installed for you automatically.
43
-
If you want to install it separately, you can install it from its [PyPI listing](https://github.com/apify/apify-sdk-python):
31
+
The Apify Python SDK is available as [`apify`](https://pypi.org/project/apify/) package on PyPi. To install it, run:
44
32
45
33
```bash
46
34
pip install apify
47
35
```
48
36
37
+
When you create an Actor using the Apify CLI, the Apify SDK for Python is installed for you automatically.
38
+
49
39
If you are not developing Apify Actors and you just need to access the Apify API from Python,
50
40
consider using the [Apify API client for Python](https://docs.apify.com/api/client/python) directly.
51
41
52
42
## Quick start
53
43
54
44
### Creating Actors
55
45
56
-
To create and run Actors through Apify Console,
57
-
see the [Console documentation](https://docs.apify.com/academy/getting-started/creating-actors#choose-your-template).
46
+
To create and run Actors through Apify Console, refer to the [Console documentation](https://docs.apify.com/academy/getting-started/creating-actors#choose-your-template).
58
47
59
-
To create a new Apify Actor on your computer, you can use the [Apify CLI](https://docs.apify.com/cli),
60
-
and select one of the [Python Actor templates](https://apify.com/templates?category=python).
48
+
To create a new Apify Actor on your computer, you can use the [Apify CLI](https://docs.apify.com/cli), and select one of the [Python Actor templates](https://apify.com/templates?category=python).
61
49
62
-
For example, to create an Actor from the "[beta] Python SDK" template,
63
-
you can use the [`apify create` command](https://docs.apify.com/cli/docs/reference#apify-create-actorname).
50
+
For example, to create an Actor from the "[beta] Python SDK" template, you can use the [`apify create` command](https://docs.apify.com/cli/docs/reference#apify-create-actorname).
This will create a new folder called `my-first-actor`,
70
-
download and extract the "Getting started with Python" Actor template there,
71
-
create a virtual environment in `my-first-actor/.venv`,
72
-
and install the Actor dependencies in it.
56
+
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.
73
57
74
58
### Running the Actor
75
59
@@ -80,27 +64,22 @@ cd my-first-actor
80
64
apify run
81
65
```
82
66
83
-
This will activate the virtual environment in `.venv` (if no other virtual environment is activated yet),
84
-
then start the Actor, passing the right environment variables for local running,
85
-
and configure it to use local storages from the `storage` folder.
67
+
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.
86
68
87
69
The Actor input, for example, will be in `storage/key_value_stores/default/INPUT.json`.
88
70
89
71
## Actor structure
90
72
91
73
All Python Actor templates follow the same structure.
92
74
93
-
The `.actor` directory contains the [Actor configuration](https://docs.apify.com/platform/actors/development/actor-config),
94
-
such as the Actor's definition and input schema, and the Dockerfile necessary to run the Actor on the Apify platform.
75
+
The `.actor` directory contains the [Actor configuration](https://docs.apify.com/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.
95
76
96
-
The Actor's runtime dependencies are specified in the `requirements.txt` file,
97
-
which follows the [standard requirements file format](https://pip.pypa.io/en/stable/reference/requirements-file-format/).
77
+
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/).
98
78
99
79
The Actor's source code is in the `src` folder. This folder contains two important files:
100
-
`main.py`, which contains the main function of the Actor,
101
-
and `__main__.py`, which is the entrypoint of the Actor package,
102
-
setting up the Actor [logger](../concepts/logging)
103
-
and executing the Actor's main function via [`asyncio.run()`](https://docs.python.org/3/library/asyncio-runner.html#asyncio.run).
80
+
81
+
-`main.py` - which contains the main function of the Actor
82
+
-`__main__.py` - which is the entrypoint of the Actor package setting up the Actor [logger](../concepts/logging) and executing the Actor's main function via [`asyncio.run()`](https://docs.python.org/3/library/asyncio-runner.html#asyncio.run).
104
83
105
84
<Tabs>
106
85
<TabItemvalue="main.py"label="main.py"default>
@@ -134,15 +113,11 @@ asyncio.run(main())`
134
113
</TabItem>
135
114
</Tabs>
136
115
137
-
If you want to modify the Actor structure,
138
-
you need to make sure that your Actor is executable as a module, via `python -m src`,
139
-
as that is the command started by `apify run` in the Apify CLI.
116
+
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.
140
117
We recommend keeping the entrypoint for the Actor in the `src/__main__.py` file.
141
118
142
119
## Adding dependencies
143
120
144
-
Adding dependencies into the Actor is simple.
145
-
146
121
First, add them in the [`requirements.txt`](https://pip.pypa.io/en/stable/reference/requirements-file-format/) file in the Actor source folder.
0 commit comments