Skip to content

feat: Make list methods of CollectionClients iterable #556

Draft
Pijukatel wants to merge 9 commits intomasterfrom
iterable-list-methods
Draft

feat: Make list methods of CollectionClients iterable #556
Pijukatel wants to merge 9 commits intomasterfrom
iterable-list-methods

Conversation

@Pijukatel
Copy link
Copy Markdown
Contributor

@Pijukatel Pijukatel commented Dec 11, 2025

Description

  • All collection clients list method returns an iterator as well.
  • All async collection clients list method returns an async iterator as well.
  • List of modified clients (same for async clients):
    • ActorCollectionClient
    • BuildCollectionClient
    • RunCollectionClient
    • ScheduleCollectionClient
    • TaskCollectionClient
    • WebhookCollectionClient
    • WebhookDispatchCollectionClient
    • DatasetCollectionClient
    • KeyValueStoreCollectionClient
    • RequestQueueCollectionClient
    • StoreCollectionClient
    • ActorEnvVarCollectionClient
    • ActorVersionCollectionClient
  • Additionally, the following storage-related list methods were modified to support iteration as well:
    • DatasetClient.list_items (and marking Dataset.iterate_items as deprecated)
    • KeyValueStoreClient.list_keys (and marking Dataset.iterate_items as deprecated)
    • RequestQueueClient.list_requests

TODO:

  • Pick proper names for the new method and interface
  • Update docs

Example usage

...
# Sync
datasets_client = ApifyClient(token='...').datasets()

# Same as before
list_page = datasets_client.list(...)

# New functionality
individual_items = [item for item in datasets_client.list(...)]

...
# Async
datasets_client = ApifyClientAsync(token='...').datasets()

# Same as before
list_page = await datasets_client.list(...)

# New functionality
individual_items = [item async for item in datasets_client.list(...)]

Issues

Testing

  • Unit tests
  • Manual API tests

Checklist

  • CI passed

@github-actions github-actions bot added this to the 129th sprint - Tooling team milestone Dec 11, 2025
@github-actions github-actions bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Dec 11, 2025
@Pijukatel Pijukatel force-pushed the iterable-list-methods branch from 9e6bb90 to fdf4b3d Compare December 11, 2025 12:35
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 99.31973% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.58%. Comparing base (be38ce0) to head (5309bc6).
⚠️ Report is 97 commits behind head on master.

Files with missing lines Patch % Lines
src/apify_client/clients/base/base_client.py 98.79% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #556      +/-   ##
==========================================
+ Coverage   76.01%   79.58%   +3.57%     
==========================================
  Files          42       42              
  Lines        2468     2508      +40     
==========================================
+ Hits         1876     1996     +120     
+ Misses        592      512      -80     
Flag Coverage Δ
integration 69.17% <80.27%> (+0.21%) ⬆️
unit 71.85% <99.31%> (+7.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Pijukatel Pijukatel force-pushed the iterable-list-methods branch 3 times, most recently from a196f2c to b561795 Compare January 7, 2026 14:34
@Pijukatel Pijukatel force-pushed the iterable-list-methods branch from b561795 to 5309bc6 Compare January 7, 2026 14:52
@Pijukatel
Copy link
Copy Markdown
Contributor Author

It is in a working state, but first, the big changes in the client will be merged. So, pausing work on this until that is done.
#481

@danpoletaev danpoletaev force-pushed the iterable-list-methods branch from 5309bc6 to cf67c9d Compare March 6, 2026 21:55
@B4nan B4nan force-pushed the iterable-list-methods branch from cf67c9d to 5309bc6 Compare March 6, 2026 22:54
Pijukatel pushed a commit that referenced this pull request Apr 17, 2026
Adds iteration support to all `list()` methods on collection clients and to
`DatasetClient.list_items()`, so callers can iterate across pages without
manually handling offset/limit/chunk_size state.

Introduces `IterableListPage` (sync) and `IterableListPageAsync` (async) in
`apify_client._iterable_list_page`. The sync wrapper exposes the page metadata
fields (`items`, `count`, `offset`, `limit`, `total`, `desc`) and is iterable;
the async wrapper is both awaitable (returns the first page) and asynchronously
iterable (yields items across pages, performing additional API calls as needed).

`DatasetClient.iterate_items()` is now deprecated — iterate the return value of
`list_items()` instead. `list_items()` also gains a `chunk_size` parameter to
control the per-request page size during iteration.

Re-creates the intent of the draft PR #556 against the current codebase, which
has since been restructured (resource clients moved under `_resource_clients/`,
a single `ResourceClient` base, typed Pydantic response models replacing the
old `ListPage` class).

Usage:

    # Sync — single page (unchanged) or iterate across pages
    page = client.datasets().list()
    for dataset in client.datasets().list():
        ...

    # Async — awaitable for single page, or async iterator across pages
    page = await client.datasets().list()
    async for dataset in client.datasets().list():
        ...

https://claude.ai/code/session_011VSSFo89Z9LfyFqZGsJKfz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants