Skip to content

Commit 4891d93

Browse files
authored
docs: Upgrade upgrading guide (#278)
1 parent 26ffb15 commit 4891d93

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

docs/03-concepts/03-storages.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ You can either use them without arguments to open the default storages,
7373
or you can pass a storage ID or name to open another storage.
7474

7575
```python title="src/main.py"
76-
from apify import Actor
76+
from apify import Actor, Request
7777

7878
async def main():
7979
async with Actor:
@@ -87,7 +87,7 @@ async def main():
8787

8888
# Work with the request queue with the name 'my-queue'
8989
request_queue = await Actor.open_request_queue(name='my-queue')
90-
await request_queue.add_request({ 'uniqueKey': 'v0Nr', 'url': 'https://example.com' })
90+
await request_queue.add_request(Request.from_url('https://example.com', unique_key='v0Nr'}))
9191
```
9292

9393
## Deleting storages
@@ -239,7 +239,7 @@ you can use the [`RequestQueue.is_finished()`](../../reference/class/RequestQueu
239239
```python title="src/main.py"
240240
import asyncio
241241
import random
242-
from apify import Actor
242+
from apify import Actor, Request
243243

244244

245245
async def main():
@@ -249,13 +249,13 @@ async def main():
249249

250250
# Add some requests to the queue
251251
for i in range(1, 10):
252-
await queue.add_request({ 'uniqueKey': f'{i}', 'url': f'http://example.com/{i}' })
252+
await queue.add_request(Request.from_url(f'http://example.com/{i}', unique_key=f'{i}'))
253253

254254
# Add a request to the start of the queue, for priority processing
255-
await queue.add_request({ 'uniqueKey': '0', 'url': 'http://example.com/0' }, forefront=True)
255+
await queue.add_request(Request.from_url(f'http://example.com/0', unique_key='0'), forefront=True)
256256

257257
# If you try to add an existing request again, it will not do anything
258-
operation_info = await queue.add_request({ 'uniqueKey': '5', 'url': 'http://different-example.com/5' })
258+
operation_info = await queue.add_request(Request.from_url(f'http://different-example.com/5', unique_key='5'))
259259
print(operation_info)
260260
print(await queue.get_request(operation_info['requestId']))
261261

docs/04-upgrading/upgrading_to_v2.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ Support for Python 3.8 has been dropped. The Apify Python SDK v2.x now requires
1111

1212
## Storages
1313

14-
The SDK now uses [crawlee](https://github.com/apify/crawlee-python) for local storage emulation. This change should not affect intended usage (working with `Dataset`, `KeyValueStore` and `RequestQueue` classes from the `apify.storages` module or using the shortcuts exposed by the `Actor` class) in any way.
15-
16-
Removing the `StorageClientManager` class is a significant change. If you need to change the storage client, use `crawlee.service_container` instead.
14+
- The SDK now uses [crawlee](https://github.com/apify/crawlee-python) for local storage emulation. This change should not affect intended usage (working with `Dataset`, `KeyValueStore` and `RequestQueue` classes from the `apify.storages` module or using the shortcuts exposed by the `Actor` class) in any way.
15+
- There is a difference in the `RequestQueue.add_request` method: it accepts an `apify.Request` object instead of a free-form dictionary.
16+
- A quick way to migrate from dict-based arguments is to wrap it with a `Request.model_validate()` call.
17+
- The preferred way is using the `Request.from_url` helper which prefills the `unique_key` and `id` attributes, or instantiating it directly, e.g., `Request(url='https://example.tld', ...)`.
18+
- For simple use cases, `add_request` also accepts plain strings that contain an URL, e.g. `queue.add_request('https://example.tld')`.
19+
- Removing the `StorageClientManager` class is a significant change. If you need to change the storage client, use `crawlee.service_container` instead.
1720

1821
## Configuration
1922

@@ -28,6 +31,7 @@ Attributes suffixed with `_millis` were renamed to remove said suffix and have t
2831
- `Actor.start`, `Actor.call`, `Actor.start_task`, `Actor.set_status_message` and `Actor.abort` return instances of the `ActorRun` model instead of an untyped `dict`.
2932
- Upon entering the context manager (`async with Actor`), the `Actor` puts the default logging configuration in place. This can be disabled using the `configure_logging` parameter.
3033
- The `config` parameter of `Actor` has been renamed to `configuration`.
34+
- Event handlers registered via `Actor.on` will now receive Pydantic objects instead of untyped dicts. For example, where you would do `event['isMigrating']`, you should now use `event.is_migrating`
3135

3236
## Scrapy integration
3337

0 commit comments

Comments
 (0)