Skip to content

Commit 2f53027

Browse files
committed
backport changes to v3
1 parent 9ebe56c commit 2f53027

13 files changed

Lines changed: 87 additions & 26 deletions

website/versioned_docs/version-3.4/01_introduction/index.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ import CodeBlock from '@theme/CodeBlock';
99

1010
import IntroductionExample from '!!raw-loader!./code/01_introduction.py';
1111

12-
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 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.
1322

1423
<CodeBlock className="language-python">
1524
{IntroductionExample}

website/versioned_docs/version-3.4/01_introduction/quick-start.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To create and run Actors in Apify Console, refer to the [Console documentation](
2121

2222
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).
2323

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).
2525

2626
```bash
2727
apify create my-first-actor --template python-start
@@ -59,15 +59,15 @@ The Actor's runtime dependencies are specified in the `requirements.txt` file, w
5959
The Actor's source code is in the `src` folder. This folder contains two important files:
6060

6161
- `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).
6363

6464
<Tabs>
6565
<TabItem value="main.py" label="main.py" default>
6666
<CodeBlock className="language-python">
6767
{MainExample}
6868
</CodeBlock>
6969
</TabItem>
70-
<TabItem value="__main__.py" label="__main.py__">
70+
<TabItem value="__main__.py" label="__main__.py">
7171
<CodeBlock className="language-python">
7272
{UnderscoreMainExample}
7373
</CodeBlock>
@@ -79,13 +79,15 @@ We recommend keeping the entrypoint for the Actor in the `src/__main__.py` file.
7979

8080
## Next steps
8181

82+
Now that you can create and run an Actor locally, explore the rest of the SDK's features and its framework integrations.
83+
8284
### Concepts
8385

8486
To learn more about the features of the Apify SDK and how to use them, check out the Concepts section in the sidebar:
8587

8688
- [Actor lifecycle](../concepts/actor-lifecycle)
8789
- [Actor input](../concepts/actor-input)
88-
- [Working with storages](../concepts/storages)
90+
- [Storages](../concepts/storages)
8991
- [Actor events & state persistence](../concepts/actor-events)
9092
- [Proxy management](../concepts/proxy-management)
9193
- [Interacting with other Actors](../concepts/interacting-with-other-actors)

website/versioned_docs/version-3.4/02_concepts/01_actor_lifecycle.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ Update the status only when the user's understanding of progress changes - avoid
106106

107107
## Conclusion
108108

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 <ApiLink to="">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 <ApiLink to="class/Actor">`Actor`</ApiLink> API reference, [guides](../guides/beautifulsoup-httpx), and [platform documentation](https://docs.apify.com/platform).

website/versioned_docs/version-3.4/02_concepts/02_actor_input.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import ApiLink from '@theme/ApiLink';
1212

1313
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).
1414

15-
To access it, instead of reading the record manually, you can use the <ApiLink to="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 <ApiLink to="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).
1616

1717
For example, if an Actor received a JSON input with two fields, `{ "firstNumber": 1, "secondNumber": 2 }`, this is how you might process it:
1818

@@ -34,4 +34,8 @@ The Apify platform supports [secret input fields](https://docs.apify.com/platfor
3434

3535
No special handling is needed in your code — when you call <ApiLink to="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.
3636

37+
## Conclusion
38+
39+
This page has shown how to read Actor input with <ApiLink to="class/Actor#get_input">`Actor.get_input`</ApiLink>, how to load URL sources with <ApiLink to="class/ApifyRequestList">`ApifyRequestList`</ApiLink>, and how secret input fields are decrypted automatically when you read them.
40+
3741
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.

website/versioned_docs/version-3.4/02_concepts/03_storages.mdx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: storages
3-
title: Working with storages
3+
title: Storages
44
description: Use datasets, key-value stores, and request queues to persist Actor data.
55
---
66

@@ -45,11 +45,11 @@ Each dataset item, key-value store record, or request in a request queue is then
4545

4646
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 <ApiLink to="class/Actor#open_dataset">`Actor.open_dataset`</ApiLink>, <ApiLink to="class/Actor#open_request_queue">`Actor.open_request_queue`</ApiLink> or <ApiLink to="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.
4747

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.
4949

5050
### Local storage persistence
5151

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.
5353

5454
```bash
5555
apify run --purge
@@ -106,8 +106,8 @@ To get an iterator of the data, you can use the <ApiLink to="class/Dataset#itera
106106
### Exporting items
107107

108108
You can also export the dataset items into a key-value store, as either a CSV or a JSON record,
109-
using the <ApiLink to="class/Dataset#export_to_csv">`Dataset.export_to_csv`</ApiLink>
110-
or <ApiLink to="class/Dataset#export_to_json">`Dataset.export_to_json`</ApiLink> method.
109+
using the <ApiLink to="class/Dataset#export_to">`Dataset.export_to`</ApiLink> method with the
110+
`content_type` argument set to `'csv'` or `'json'`.
111111

112112
<RunnableCodeBlock className="language-python" language="python">
113113
{DatasetExportsExample}
@@ -183,6 +183,10 @@ To check if all the requests in the queue are handled, you can use the <ApiLink
183183

184184
## Storage clients
185185

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. 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.
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.
187191

188192
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).

website/versioned_docs/version-3.4/02_concepts/04_actor_events.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,8 @@ You can optionally specify a `key` (the key-value store key under which the stat
103103
{UseStateExample}
104104
</RunnableCodeBlock>
105105

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 <ApiLink to="class/Actor#on">`Actor.on`</ApiLink>, and how to persist state automatically with <ApiLink to="class/Actor#use_state">`Actor.use_state`</ApiLink>.
109+
106110
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.

website/versioned_docs/version-3.4/02_concepts/05_proxy_management.mdx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The Apify SDK provides built-in proxy management through the <ApiLink to="class/
2222

2323
If you want to use Apify Proxy locally, make sure that you run your Actors via the Apify CLI and that you are [logged in](https://docs.apify.com/cli/docs/installation#login-with-your-apify-account) with your Apify account in the CLI.
2424

25-
### Using Apify proxy
25+
### Using Apify Proxy
2626

2727
<RunnableCodeBlock className="language-python" language="python">
2828
{ApifyProxyExample}
@@ -38,7 +38,7 @@ If you want to use Apify Proxy locally, make sure that you run your Actors via t
3838

3939
All your proxy needs are managed by the <ApiLink to="class/ProxyConfiguration">`ProxyConfiguration`</ApiLink> class. You create an instance using the <ApiLink to="class/Actor#create_proxy_configuration">`Actor.create_proxy_configuration()`</ApiLink> method. Then you generate proxy URLs using the <ApiLink to="class/ProxyConfiguration#new_url">`ProxyConfiguration.new_url()`</ApiLink> method.
4040

41-
### Apify proxy vs. your own proxies
41+
### Apify Proxy vs. your own proxies
4242

4343
The `ProxyConfiguration` class covers both Apify Proxy and custom proxy URLs, so that you can easily switch between proxy providers. However, some features of the class are available only to Apify Proxy users, mainly because Apify Proxy is what one would call a super-proxy. It's not a single proxy server, but an API endpoint that allows connection through millions of different IP addresses. So the class essentially has two modes: Apify Proxy or Your proxy.
4444

@@ -54,7 +54,7 @@ When no `session_id` is provided, your custom proxy URLs are rotated round-robin
5454
{ProxyRotationExample}
5555
</RunnableCodeBlock>
5656

57-
### Apify proxy configuration
57+
### Apify Proxy configuration
5858

5959
With Apify Proxy, you can select specific proxy groups to use, or countries to connect from. For even finer control, you can also target a specific subdivision (e.g. a US state) using the `subdivision_code` parameter alongside `country_code`. This allows you to get better proxy performance after some initial research.
6060

@@ -106,9 +106,11 @@ You can then use that input to create the proxy configuration:
106106

107107
## Using the generated proxy URLs
108108

109+
`ProxyConfiguration` only generates proxy URLs. It doesn't make requests. To route requests through the proxy, pass a generated URL to the HTTP client your Actor uses.
110+
109111
### HTTPX
110112

111-
To use the generated proxy URLs with the `httpx` library, use the [`proxies`](https://www.python-httpx.org/advanced/#http-proxying) argument:
113+
To use the generated proxy URLs with the `httpx` library, use the [`proxy`](https://www.python-httpx.org/advanced/proxies/) argument:
112114

113115
<RunnableCodeBlock className="language-python" language="python">
114116
{ProxyHttpxExample}
@@ -120,4 +122,8 @@ Make sure you have the `httpx` library installed:
120122
pip install httpx
121123
```
122124

125+
## Conclusion
126+
127+
This page has explained how to manage proxies with the <ApiLink to="class/ProxyConfiguration">`ProxyConfiguration`</ApiLink> class: using Apify Proxy or your own servers, keeping sessions sticky across requests, configuring tiered proxy rotation, and feeding proxy settings from Actor input.
128+
123129
For full details on proxy configuration options, see the <ApiLink to="class/ProxyConfiguration">`ProxyConfiguration`</ApiLink> API reference and the [Apify Proxy documentation](https://docs.apify.com/proxy).

website/versioned_docs/version-3.4/02_concepts/06_interacting_with_other_actors.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ When you set `gracefully=True`, the platform sends `ABORTING` and `PERSIST_STATE
6363
{InteractingAbortExample}
6464
</RunnableCodeBlock>
6565

66+
## Conclusion
67+
68+
This page has shown how to interact with other Actors from your code: starting a run with <ApiLink to="class/Actor#start">`Actor.start`</ApiLink>, waiting for it to finish with <ApiLink to="class/Actor#call">`Actor.call`</ApiLink> or <ApiLink to="class/Actor#call_task">`Actor.call_task`</ApiLink>, transforming a run with <ApiLink to="class/Actor#metamorph">`Actor.metamorph`</ApiLink>, and stopping one with <ApiLink to="class/Actor#abort">`Actor.abort`</ApiLink>.
69+
6670
For the full list of methods for interacting with other Actors, see the <ApiLink to="class/Actor">`Actor`</ApiLink> API reference. For more details on running Actors and Actor tasks on the platform, see the [Actors](https://docs.apify.com/platform/actors) and [Actor tasks](https://docs.apify.com/platform/actors/tasks) documentation.

website/versioned_docs/version-3.4/02_concepts/07_webhooks.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ To ensure that duplicate ad-hoc webhooks won't get created in a case of Actor re
3232
{WebhookPreventingExample}
3333
</RunnableCodeBlock>
3434

35+
## Conclusion
36+
37+
This page has shown how to create ad-hoc webhooks dynamically with <ApiLink to="class/Actor#add_webhook">`Actor.add_webhook`</ApiLink> and how to avoid creating duplicates across Actor restarts using the `idempotency_key` parameter.
38+
3539
For more information about webhooks, including event types and payloads, see the [Apify webhooks documentation](https://docs.apify.com/platform/integrations/webhooks).

0 commit comments

Comments
 (0)