Skip to content

Commit c8a42b8

Browse files
committed
More review comments
1 parent 124237c commit c8a42b8

5 files changed

Lines changed: 26 additions & 20 deletions

File tree

docs/02_concepts/08_pagination.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import ApiLink from '@site/src/components/ApiLink';
1212

1313
import PaginationAsyncExample from '!!raw-loader!./code/08_pagination_async.py';
1414
import PaginationSyncExample from '!!raw-loader!./code/08_pagination_sync.py';
15+
import IterateItemsAsyncExample from '!!raw-loader!./code/08_iterate_items_async.py';
16+
import IterateItemsSyncExample from '!!raw-loader!./code/08_iterate_items_sync.py';
1517

1618

1719
Most methods named `list` or `list_something` in the Apify client return a <ApiLink to="class/ListPage">`ListPage`</ApiLink> object. This object provides a consistent interface for working with paginated data and includes the following properties:

src/apify_client/_iterable_list_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def __aiter__(self) -> AsyncIterator[T]:
124124
return self._get_async_iterator()
125125

126126
def __await__(self) -> Generator[Any, Any, ListPage[T]]:
127-
"""Return an awaitable that resolves to an `IterableListPage` containing the first page."""
127+
"""Return an awaitable that resolves to a `ListPage` containing the first page of results."""
128128
return self._awaitable_first_page().__await__()
129129

130130

src/apify_client/_resource_clients/key_value_store.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,14 @@ def list_keys(
162162
https://docs.apify.com/api/v2#/reference/key-value-stores/key-collection/get-list-of-keys
163163
164164
Args:
165-
limit: Number of keys to be returned. Maximum value is 1000.
165+
limit: Total number of keys to yield across all pages when iterating. The API caps each
166+
individual request at 1000 keys; use `chunk_size` to control the per-request size.
166167
exclusive_start_key: All keys up to this one (including) are skipped from the result.
167168
collection: The name of the collection in store schema to list keys from.
168169
prefix: The prefix of the keys to be listed.
169170
signature: Signature used to access the items.
170-
chunk_size: Maximum number of keys requested per API call when iterating. Only relevant
171-
when iterating across pages.
171+
chunk_size: Maximum number of keys requested per API call when iterating. Capped at
172+
1000 by the API. Only relevant when iterating across pages.
172173
timeout: Timeout for the API HTTP request.
173174
174175
Returns:
@@ -218,13 +219,14 @@ def iterate_keys(
218219
https://docs.apify.com/api/v2#/reference/key-value-stores/key-collection/get-list-of-keys
219220
220221
Args:
221-
limit: Number of keys to be returned. Maximum value is 1000.
222+
limit: Total number of keys to yield across all pages. The API caps each individual
223+
request at 1000 keys; use `chunk_size` to control the per-request size.
222224
exclusive_start_key: All keys up to this one (including) are skipped from the result.
223225
collection: The name of the collection in store schema to list keys from.
224226
prefix: The prefix of the keys to be listed.
225227
signature: Signature used to access the items.
226-
chunk_size: Maximum number of keys requested per API call when iterating. Only relevant
227-
when iterating across pages.
228+
chunk_size: Maximum number of keys requested per API call when iterating. Capped at
229+
1000 by the API. Only relevant when iterating across pages.
228230
timeout: Timeout for the API HTTP request.
229231
230232
Yields:
@@ -476,7 +478,7 @@ def create_keys_public_url(
476478
Any other options (like `limit` or `prefix`) will be included as query parameters in the URL.
477479
478480
Args:
479-
limit: Number of keys to be returned. Maximum value is 1000.
481+
limit: Number of keys to be returned by the signed request. Maximum value is 1000.
480482
exclusive_start_key: All keys up to this one (including) are skipped from the result.
481483
collection: The name of the collection in store schema to list keys from.
482484
prefix: The prefix of the keys to be listed.
@@ -600,13 +602,14 @@ def list_keys(
600602
https://docs.apify.com/api/v2#/reference/key-value-stores/key-collection/get-list-of-keys
601603
602604
Args:
603-
limit: Number of keys to be returned. Maximum value is 1000.
605+
limit: Total number of keys to yield across all pages when iterating. The API caps each
606+
individual request at 1000 keys; use `chunk_size` to control the per-request size.
604607
exclusive_start_key: All keys up to this one (including) are skipped from the result.
605608
collection: The name of the collection in store schema to list keys from.
606609
prefix: The prefix of the keys to be listed.
607610
signature: Signature used to access the items.
608-
chunk_size: Maximum number of keys requested per API call when iterating. Only relevant
609-
when iterating across pages.
611+
chunk_size: Maximum number of keys requested per API call when iterating. Capped at
612+
1000 by the API. Only relevant when iterating across pages.
610613
timeout: Timeout for the API HTTP request.
611614
612615
Returns:
@@ -656,13 +659,14 @@ async def iterate_keys(
656659
https://docs.apify.com/api/v2#/reference/key-value-stores/key-collection/get-list-of-keys
657660
658661
Args:
659-
limit: Number of keys to be returned. Maximum value is 1000.
662+
limit: Total number of keys to yield across all pages. The API caps each individual
663+
request at 1000 keys; use `chunk_size` to control the per-request size.
660664
exclusive_start_key: All keys up to this one (including) are skipped from the result.
661665
collection: The name of the collection in store schema to list keys from.
662666
prefix: The prefix of the keys to be listed.
663667
signature: Signature used to access the items.
664-
chunk_size: Maximum number of keys requested per API call when iterating. Only relevant
665-
when iterating across pages.
668+
chunk_size: Maximum number of keys requested per API call when iterating. Capped at
669+
1000 by the API. Only relevant when iterating across pages.
666670
timeout: Timeout for the API HTTP request.
667671
668672
Yields:
@@ -917,7 +921,7 @@ async def create_keys_public_url(
917921
Any other options (like `limit` or `prefix`) will be included as query parameters in the URL.
918922
919923
Args:
920-
limit: Number of keys to be returned. Maximum value is 1000.
924+
limit: Number of keys to be returned by the signed request. Maximum value is 1000.
921925
exclusive_start_key: All keys up to this one (including) are skipped from the result.
922926
collection: The name of the collection in store schema to list keys from.
923927
prefix: The prefix of the keys to be listed.

tests/integration/test_request_queue.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ async def test_request_queue_list_requests(client: ApifyClient | ApifyClientAsyn
265265

266266
assert isinstance(list_response, ListPage)
267267
assert isinstance(list_response.items, list)
268-
assert isinstance(list_response.items[0], Request)
269268
assert len(list_response.items) == 5
269+
assert isinstance(list_response.items[0], Request)
270270
finally:
271271
await maybe_await(rq_client.delete())
272272

@@ -335,8 +335,8 @@ async def test_request_queue_batch_add_requests(client: ApifyClient | ApifyClien
335335

336336
assert isinstance(list_response, ListPage)
337337
assert isinstance(list_response.items, list)
338-
assert isinstance(list_response.items[0], Request)
339338
assert len(list_response.items) == 10
339+
assert isinstance(list_response.items[0], Request)
340340
finally:
341341
await maybe_await(rq_client.delete())
342342

@@ -366,8 +366,8 @@ async def test_request_queue_batch_delete_requests(client: ApifyClient | ApifyCl
366366

367367
assert isinstance(list_response, ListPage)
368368
assert isinstance(list_response.items, list)
369-
assert isinstance(list_response.items[0], Request)
370369
assert len(list_response.items) == 10
370+
assert isinstance(list_response.items[0], Request)
371371
requests_to_delete: list[RequestDeleteInputDict] = [
372372
{'unique_key': item.unique_key} for item in list_response.items[:5]
373373
]
@@ -388,8 +388,8 @@ async def test_request_queue_batch_delete_requests(client: ApifyClient | ApifyCl
388388

389389
assert isinstance(remaining, ListPage)
390390
assert isinstance(remaining.items, list)
391-
assert isinstance(remaining.items[0], Request)
392391
assert len(remaining.items) == 5
392+
assert isinstance(remaining.items[0], Request)
393393
finally:
394394
await maybe_await(rq_client.delete())
395395

tests/integration/test_webhook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ async def test_webhook_dispatches(client: ApifyClient | ApifyClientAsync) -> Non
173173
dispatches = await maybe_await(webhook_client.dispatches().list())
174174
assert isinstance(dispatches, ListPage)
175175
assert isinstance(dispatches.items, list)
176-
assert isinstance(dispatches.items[0], WebhookDispatch)
177176
assert len(dispatches.items) > 0
177+
assert isinstance(dispatches.items[0], WebhookDispatch)
178178

179179
finally:
180180
await maybe_await(webhook_client.delete())

0 commit comments

Comments
 (0)