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
Most methods named `list` or `list_something` in the Apify client return a <ApiLinkto="class/ListPage">`ListPage`</ApiLink> object. This object provides a consistent interface for working with paginated data and includes the following properties:
20
21
@@ -45,21 +46,38 @@ The <ApiLink to="class/ListPage">`ListPage`</ApiLink> interface offers several k
45
46
46
47
## Generator-based iteration
47
48
48
-
For most use cases, `iterate_items()` is the recommended way to process all items in a dataset. It handles pagination automatically using a Python generator, fetching items in batches behind the scenes so you don't need to manage offsets or limits yourself.
49
+
For collection clients, the `iterate` method returns an iterator that lazily fetches as many pages as needed
50
+
to retrieve every item matching the filters. For dataset, key-value store and request queue clients, the
51
+
matching helpers are `iterate_items`, `iterate_keys` and `iterate_requests`. They handle pagination
52
+
automatically, so you don't need to manage offsets, limits or cursors yourself.
53
+
54
+
The example below iterates over every Actor owned by the current user using a collection client's `iterate`
`iterate_items()` accepts the same filtering parameters as `list_items()` (`clean`, `fields`, `omit`, `unwind`, `skip_empty`, `skip_hidden`), so you can combine automatic pagination with data filtering.
70
+
The next example uses `iterate_items` on a dataset client to stream items past a given offset:
64
71
65
-
Similarly, `KeyValueStoreClient` provides an `iterate_keys()` method for iterating over all keys in a key-value store without manual pagination.
## Async `iterate_*` methods are plain functions, not async generators
325
+
326
+
Async iteration helpers — <ApiLinkto="class/DatasetClientAsync#iterate_items">`DatasetClientAsync.iterate_items()`</ApiLink> and <ApiLinkto="class/KeyValueStoreClientAsync#iterate_keys">`KeyValueStoreClientAsync.iterate_keys()`</ApiLink> — were previously declared as `async def` (async generator functions). They are now plain `def` functions that return an `AsyncIterator` produced by a shared pagination helper.
327
+
328
+
Consumer-side iteration is unchanged — `async for item in client.iterate_items(...)` works the same in both versions:
329
+
330
+
```python
331
+
# Works in both v2 and v3
332
+
asyncfor item in client.dataset('my-dataset').iterate_items():
333
+
print(item)
334
+
```
335
+
336
+
The difference matters only if your code inspects the function itself:
337
+
338
+
- The call is no longer a coroutine function — `inspect.iscoroutinefunction(client.iterate_items)` returns `False`, and `inspect.isasyncgenfunction(client.iterate_items)` also returns `False` (it returns a regular function whose result is an async iterator).
339
+
- Type checkers see `def (...) -> AsyncIterator[T]` instead of `async def (...) -> AsyncIterator[T]`. Annotations on variables that hold the call's result may need to change from `AsyncGenerator[T, None]` to `AsyncIterator[T]`.
340
+
341
+
A new <ApiLinkto="class/RequestQueueClientAsync#iterate_requests">`RequestQueueClientAsync.iterate_requests()`</ApiLink> helper is also introduced and follows the same `def ... -> AsyncIterator[T]` shape.
0 commit comments