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
{{ message }}
Repository navigation
Commit f96817d
Browse filesBrowse the repository at this point in the historyBrowse files
docs: Fix inaccuracies, unify wording, and expand SDK documentation (#921)
Reviews the SDK documentation (Introduction, Concepts, Upgrading)
against the codebase — fixes verified inaccuracies, unifies wording, and
fills a few gaps. Does not touch the Guides section; those changes live
in #939.
## Correctness fixes
- **Storages**: documented the real `Dataset.export_to`
(`content_type='csv'|'json'`); `export_to_csv`/`export_to_json` don't
exist.
- **Upgrading to v2**: `Actor.start_task` → `Actor.call_task` (accepts
`Webhook`, returns `ActorRun`).
- **Introduction**: Python requirement `3.10+` → `3.11+`.
- **CONTRIBUTING**: development Python requirement `3.10` → `3.11`.
- **PyPI metadata**: the "Release Notes" URL in `pyproject.toml` pointed
at the v2 upgrade guide; now points at the v4 guide (wheel metadata is
immutable after publish).
- **Actor events**: corrected the `SYSTEM_INFO` / `MIGRATING` payloads
and `Config` → `Configuration`, each event now links its real data type;
fixed `04_actor_events.py` (passing a Pydantic model as logging `extra=`
raises `TypeError`).
- **Configuration**: `APIFY_PERSIST_STORAGE=0` →
`APIFY_PURGE_ON_START=0`.
- **Actor lifecycle**: fixed an empty `<ApiLink>`.
- **Quick-start**: corrected the `__main__.py` description and tab
label.
## Consistency & additions
- Consistent capitalization ("Apify Proxy", "Apify Console", "Actor");
assorted grammar and upgrade-guide heading fixes; made an absolute
self-link relative.
- New **Storage clients** concept page with two runnable snippets
(default `SmartApifyStorageClient`, single vs. shared request queue,
`force_cloud`, custom client via `service_locator`); re-exported
`StorageClient` from `apify.storage_clients`.
- Added a `## Conclusion` to every concept page, expanded the
Introduction feature list, and added a Configuration options table.
## TODO before merging
- [ ] Mirror these changes into `website/versioned_docs/version-3.4/` so
the published docs version reflects them, not only under "next": apply
the edits to the existing Introduction, Concepts, and Upgrading pages,
and clone the new Storage clients page
(`docs/02_concepts/12_storage_clients.mdx` + its `code/12_*.py`
snippets).
The Apify SDK for Python is the official library for creating [Apify Actors](https://docs.apify.com/platform/actors) in Python. It provides useful features like Actor lifecycle management, local storage emulation, and Actor event handling.
12
+
The Apify SDK for Python is the official library for creating [Apify Actors](https://docs.apify.com/platform/actors) in Python. It provides everything you need to build an Actor and run it both locally and on the [Apify platform](https://docs.apify.com/platform). With the SDK, you can:
13
+
14
+
- Manage the Actor lifecycle: initialization, graceful shutdown, status messages, rebooting, and metamorphing.
15
+
- Work with datasets, key-value stores, and request queues, with automatic local emulation when running outside the platform.
16
+
- Read the Actor input, including automatic decryption of secret fields.
17
+
- React to platform events (system info, migration, abort) and persist state across migrations and restarts.
18
+
- Manage proxies, both [Apify Proxy](https://docs.apify.com/platform/proxy) and your own, with session and tiered-proxy support.
19
+
- Start, call, and abort Actors and tasks, create webhooks, and reach the full Apify API client.
20
+
- Charge users with the pay-per-event pricing model.
21
+
- Integrate with [Crawlee](../guides/crawlee) and [Scrapy](../guides/scrapy), with guides for [Playwright](../guides/playwright) and others.
13
22
14
23
<CodeBlockclassName="language-python">
15
24
{IntroductionExample}
@@ -29,7 +38,7 @@ Explore the Guides section in the sidebar for a deeper understanding of the SDK'
29
38
30
39
## Installation
31
40
32
-
The Apify SDK for Python requires Python version 3.10 or above. It is typically installed when you create a new Actor project using the [Apify CLI](https://docs.apify.com/cli). To install it manually in an existing project, use:
41
+
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](https://docs.apify.com/cli). To install it manually in an existing project, use:
Copy file name to clipboardExpand all lines: docs/01_introduction/quick-start.mdx
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,11 +17,11 @@ import UnderscoreMainExample from '!!raw-loader!./code/actor_structure/__main__.
17
17
18
18
## Step 1: Create Actors
19
19
20
-
To create and run Actors in Apify Console, refer to the [Console documentation](/platform/actors/development/quick-start/web-ide).
20
+
To create and run Actors in [Apify Console](https://docs.apify.com/platform/console), refer to the [Console documentation](/platform/actors/development/quick-start/web-ide).
21
21
22
22
To create a new Apify Actor on your computer, you can use the [Apify CLI](/cli), and select one of the [Python Actor templates](https://apify.com/templates?category=python).
23
23
24
-
For example, to create an Actor from the "[beta] Python SDK" template, you can use the [`apify create` command](/cli/docs/reference#apify-create-actorname).
24
+
For example, to create an Actor from the "Getting started with Python" template, you can use the [`apify create` command](/cli/docs/reference#apify-create-actorname).
@@ -59,15 +59,15 @@ The Actor's runtime dependencies are specified in the `requirements.txt` file, w
59
59
The Actor's source code is in the `src` folder. This folder contains two important files:
60
60
61
61
-`main.py` - which contains the main function of the Actor
62
-
-`__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).
62
+
-`__main__.py` - which is the entrypoint of the Actor package, executing the Actor's main function via [`asyncio.run()`](https://docs.python.org/3/library/asyncio-runner.html#asyncio.run).
63
63
64
64
<Tabs>
65
65
<TabItemvalue="main.py"label="main.py"default>
66
66
<CodeBlockclassName="language-python">
67
67
{MainExample}
68
68
</CodeBlock>
69
69
</TabItem>
70
-
<TabItemvalue="__main__.py"label="__main.py__">
70
+
<TabItemvalue="__main__.py"label="__main__.py">
71
71
<CodeBlockclassName="language-python">
72
72
{UnderscoreMainExample}
73
73
</CodeBlock>
@@ -79,13 +79,15 @@ We recommend keeping the entrypoint for the Actor in the `src/__main__.py` file.
79
79
80
80
## Next steps
81
81
82
+
Now that you can create and run an Actor locally, explore the rest of the SDK's features and its framework integrations.
83
+
82
84
### Concepts
83
85
84
86
To learn more about the features of the Apify SDK and how to use them, check out the Concepts section in the sidebar:
85
87
86
88
-[Actor lifecycle](../concepts/actor-lifecycle)
87
89
-[Actor input](../concepts/actor-input)
88
-
-[Working with storages](../concepts/storages)
90
+
-[Storages](../concepts/storages)
89
91
-[Actor events & state persistence](../concepts/actor-events)
90
92
-[Proxy management](../concepts/proxy-management)
91
93
-[Interacting with other Actors](../concepts/interacting-with-other-actors)
@@ -94,6 +96,7 @@ To learn more about the features of the Apify SDK and how to use them, check out
This guide explains how an **Apify Actor** starts, runs, and shuts down, describing the complete Actor lifecycle. For information about the core concepts such as Actors, the Apify Console, storages, and events, check out the [Apify platform documentation](https://docs.apify.com/platform).
24
+
This guide explains how an **Apify Actor** starts, runs, and shuts down, describing the complete Actor lifecycle. For information about the core concepts such as Actors, the [Apify Console](https://docs.apify.com/platform/console), storages, and events, check out the [Apify platform documentation](https://docs.apify.com/platform).
25
25
26
26
## Actor initialization
27
27
@@ -106,4 +106,4 @@ Update the status only when the user's understanding of progress changes - avoid
106
106
107
107
## Conclusion
108
108
109
-
This page has presented the full Actor lifecycle: initialization, execution, error handling, rebooting, shutdown and status messages. You've seen how the SDK supports both context-based and manual control patterns. For deeper dives, explore the <ApiLinkto="">reference docs</ApiLink>, [guides](https://docs.apify.com/sdk/python/docs/guides/beautifulsoup-httpx), and [platform documentation](https://docs.apify.com/platform).
109
+
This page has presented the full Actor lifecycle: initialization, execution, error handling, rebooting, shutdown and status messages. You've seen how the SDK supports both context-based and manual control patterns. For deeper dives, explore the <ApiLinkto="class/Actor">`Actor`</ApiLink> API reference, [guides](../guides/beautifulsoup-httpx), and [platform documentation](https://docs.apify.com/platform).
Copy file name to clipboardExpand all lines: docs/02_concepts/02_actor_input.mdx
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ import ApiLink from '@theme/ApiLink';
12
12
13
13
The Actor gets its [input](https://docs.apify.com/platform/actors/running/input) from the input record in its default [key-value store](https://docs.apify.com/platform/storage/key-value-store).
14
14
15
-
To access it, instead of reading the record manually, you can use the <ApiLinkto="class/Actor#get_input">`Actor.get_input`</ApiLink> convenience method. It will get the input record key from the Actor configuration, read the record from the default key-value store,and decrypt any [secret input fields](https://docs.apify.com/platform/actors/development/secret-input).
15
+
To access it, instead of reading the record manually, you can use the <ApiLinkto="class/Actor#get_input">`Actor.get_input`</ApiLink> convenience method. It gets the input record key from the Actor configuration, reads the record from the default key-value store,and decrypts any [secret input fields](https://docs.apify.com/platform/actors/development/secret-input).
16
16
17
17
For example, if an Actor received a JSON input with two fields, `{ "firstNumber": 1, "secondNumber": 2 }`, this is how you might process it:
No special handling is needed in your code — when you call <ApiLinkto="class/Actor#get_input">`Actor.get_input`</ApiLink>, encrypted fields are automatically decrypted using the Actor's private key, which is provided by the platform via environment variables. You receive the plaintext values directly.
40
40
41
+
## Conclusion
42
+
43
+
This page has shown how to read Actor input with <ApiLinkto="class/Actor#get_input">`Actor.get_input`</ApiLink>, how to load URL sources with <ApiLinkto="class/ApifyRequestList">`ApifyRequestList`</ApiLink>, and how secret input fields are decrypted automatically when you read them.
44
+
41
45
For more details on Actor input and how to define input schemas, see the [Actor input](https://docs.apify.com/platform/actors/running/input) and [input schema](https://docs.apify.com/platform/actors/development/input-schema) documentation on the Apify platform.
Copy file name to clipboardExpand all lines: docs/02_concepts/03_storages.mdx
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
id: storages
3
-
title: Working with storages
3
+
title: Storages
4
4
description: Use datasets, key-value stores, and request queues to persist Actor data.
5
5
---
6
6
@@ -45,11 +45,11 @@ Each dataset item, key-value store record, or request in a request queue is then
45
45
46
46
When developing locally, opening any storage will by default use local storage. To change this behavior and to use remote storage you have to use `force_cloud=True` argument in <ApiLinkto="class/Actor#open_dataset">`Actor.open_dataset`</ApiLink>, <ApiLinkto="class/Actor#open_request_queue">`Actor.open_request_queue`</ApiLink> or <ApiLinkto="class/Actor#open_key_value_store">`Actor.open_key_value_store`</ApiLink>. Proper use of this argument allows you to work with both local and remote storages.
47
47
48
-
Calling another remote Actor and accessing its default storage is typical use-case for using `force-cloud=True` argument to open remote Actor's storages.
48
+
Calling another remote Actor and accessing its default storage is a typical use-case for using `force_cloud=True` argument to open remote Actor's storages.
49
49
50
50
### Local storage persistence
51
51
52
-
By default, the storage contents are persisted across multiple Actor runs. To clean up the Actor storages before the running the Actor, use the `--purge` flag of the [`apify run`](https://docs.apify.com/cli/docs/reference#apify-run) command of the Apify CLI.
52
+
By default, the storage contents are persisted across multiple Actor runs. To clean up the Actor storages before running the Actor, use the `--purge` flag of the [`apify run`](https://docs.apify.com/cli/docs/reference#apify-run) command of the Apify CLI.
53
53
54
54
```bash
55
55
apify run --purge
@@ -106,8 +106,8 @@ To get an iterator of the data, you can use the <ApiLink to="class/Dataset#itera
106
106
### Exporting items
107
107
108
108
You can also export the dataset items into a key-value store, as either a CSV or a JSON record,
109
-
using the <ApiLinkto="class/Dataset#export_to_csv">`Dataset.export_to_csv`</ApiLink>
110
-
or <ApiLinkto="class/Dataset#export_to_json">`Dataset.export_to_json`</ApiLink> method.
109
+
using the <ApiLinkto="class/Dataset#export_to">`Dataset.export_to`</ApiLink> method with the
110
+
`content_type` argument set to `'csv'` or `'json'`.
@@ -183,6 +183,10 @@ To check if all the requests in the queue are handled, you can use the <ApiLink
183
183
184
184
## Storage clients
185
185
186
-
Behind the scenes, the SDK uses storage clients to communicate with the storage backend. The appropriate client is selected automatically based on the runtime environment — on the Apify platform, data is persisted via the Apify API, while local runs use the filesystem. For most use cases, you don't need to think about storage clients at all. If you want to learn more about how storage clients work, the available implementations, or how to configure them, see the [Crawlee storage clients guide](https://crawlee.dev/python/docs/guides/storage-clients). The Apify-specific clients are available in the `apify.storage_clients` module.
186
+
Behind the scenes, the SDK uses storage clients to communicate with the storage backend. The appropriate client is selected automatically based on the runtime environment. On the Apify platform, data is persisted via the Apify API, while local runs use the filesystem. For most use cases, you don't need to think about storage clients at all. To learn about the available implementations, how to switch between a single and shared request queue, or how to configure a custom client, see [Storage clients](./storage-clients). For a deeper look at how storage clients work internally, see the [Crawlee storage clients guide](https://crawlee.dev/python/docs/guides/storage-clients).
187
+
188
+
## Conclusion
189
+
190
+
This page has covered the three storage types (datasets, key-value stores, and request queues): how they are emulated on the local filesystem, how to open named and unnamed storages, and how to read from and write to each through the `Actor` shortcuts and the storage classes.
187
191
188
192
For comprehensive information about storage on the Apify platform, see the [storage documentation](https://docs.apify.com/platform/storage), including the pages on [datasets](https://docs.apify.com/platform/storage/dataset), [key-value stores](https://docs.apify.com/platform/storage/key-value-store), and [request queues](https://docs.apify.com/platform/storage/request-queue).
Copy file name to clipboardExpand all lines: docs/02_concepts/04_actor_events.mdx
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,8 @@ During its runtime, the Actor receives Actor events sent by the Apify platform o
14
14
15
15
## Event types
16
16
17
+
A listener can optionally receive a single argument, a Pydantic model with the event's data. The following table lists the events, the type of that data object, and when each event is emitted.
18
+
17
19
<table>
18
20
<thead>
19
21
<tr>
@@ -25,25 +27,23 @@ During its runtime, the Actor receives Actor events sent by the Apify platform o
Emitted by the SDK (not the platform) when the Actor is about to exit. You can use this event to perform final cleanup tasks,
79
79
such as closing external connections or sending notifications, before the Actor shuts down.
@@ -103,4 +103,8 @@ You can optionally specify a `key` (the key-value store key under which the stat
103
103
{UseStateExample}
104
104
</RunnableCodeBlock>
105
105
106
+
## Conclusion
107
+
108
+
This page has described the events emitted during a run (`SYSTEM_INFO`, `MIGRATING`, `ABORTING`, `PERSIST_STATE`, and `EXIT`): how to handle them with <ApiLinkto="class/Actor#on">`Actor.on`</ApiLink>, and how to persist state automatically with <ApiLinkto="class/Actor#use_state">`Actor.use_state`</ApiLink>.
109
+
106
110
For more details on platform events and state persistence, see the [system events](https://docs.apify.com/platform/actors/development/programming-interface/system-events) and [state persistence](https://docs.apify.com/platform/actors/development/state-persistence) documentation on the Apify platform.
0 commit comments