Skip to content

chore: Move ListPage from apify_shared #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions src/apify_client/clients/base/resource_collection_client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
from __future__ import annotations

from typing import Any
from typing import Any, Generic, TypeVar

from apify_shared.models import ListPage
from apify_shared.utils import ignore_docs, parse_date_fields

from apify_client._utils import pluck_data
from apify_client.clients.base.base_client import BaseClient, BaseClientAsync

T = TypeVar('T')


class ListPage(Generic[T]):
"""A single page of items returned from a list() method."""

items: list[T]
"""List of returned objects on this page"""

count: int
"""Count of the returned objects on this page"""

offset: int
"""The limit on the number of returned objects offset specified in the API call"""

limit: int
"""The offset of the first object specified in the API call"""

total: int
"""Total number of objects matching the API call criteria"""

desc: bool
"""Whether the listing is descending or not"""

@ignore_docs
def __init__(self, data: dict) -> None:
"""Initialize a ListPage instance from the API response data."""
self.items = data.get('items', [])
self.offset = data.get('offset', 0)
self.limit = data.get('limit', 0)
self.count = data['count'] if 'count' in data else len(self.items)
self.total = data['total'] if 'total' in data else self.offset + self.count
self.desc = data.get('desc', False)


@ignore_docs
class ResourceCollectionClient(BaseClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from apify_client.clients.resource_clients.actor import get_actor_representation

if TYPE_CHECKING:
from apify_shared.models import ListPage
from apify_client.clients.base.resource_collection_client import ListPage


class ActorCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from apify_client.clients.resource_clients.actor_env_var import get_actor_env_var_representation

if TYPE_CHECKING:
from apify_shared.models import ListPage
from apify_client.clients.base.resource_collection_client import ListPage


class ActorEnvVarCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

if TYPE_CHECKING:
from apify_shared.consts import ActorSourceType
from apify_shared.models import ListPage

from apify_client.clients.base.resource_collection_client import ListPage


class ActorVersionCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync

if TYPE_CHECKING:
from apify_shared.models import ListPage
from apify_client.clients.base.resource_collection_client import ListPage


class BuildCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync

if TYPE_CHECKING:
from apify_shared.models import ListPage
from apify_client.clients.base.resource_collection_client import ListPage


class DatasetCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync

if TYPE_CHECKING:
from apify_shared.models import ListPage
from apify_client.clients.base.resource_collection_client import ListPage


class KeyValueStoreCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync

if TYPE_CHECKING:
from apify_shared.models import ListPage
from apify_client.clients.base.resource_collection_client import ListPage


class RequestQueueCollectionClient(ResourceCollectionClient):
Expand Down
3 changes: 2 additions & 1 deletion src/apify_client/clients/resource_clients/run_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

if TYPE_CHECKING:
from apify_shared.consts import ActorJobStatus
from apify_shared.models import ListPage

from apify_client.clients.base.resource_collection_client import ListPage


class RunCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from apify_client.clients.resource_clients.schedule import _get_schedule_representation

if TYPE_CHECKING:
from apify_shared.models import ListPage
from apify_client.clients.base.resource_collection_client import ListPage


class ScheduleCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync

if TYPE_CHECKING:
from apify_shared.models import ListPage
from apify_client.clients.base.resource_collection_client import ListPage


class StoreCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from apify_client.clients.resource_clients.task import get_task_representation

if TYPE_CHECKING:
from apify_shared.models import ListPage
from apify_client.clients.base.resource_collection_client import ListPage


class TaskCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

if TYPE_CHECKING:
from apify_shared.consts import WebhookEventType
from apify_shared.models import ListPage

from apify_client.clients.base.resource_collection_client import ListPage


class WebhookCollectionClient(ResourceCollectionClient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from apify_client.clients.base import ResourceCollectionClient, ResourceCollectionClientAsync

if TYPE_CHECKING:
from apify_shared.models import ListPage
from apify_client.clients.base.resource_collection_client import ListPage


class WebhookDispatchCollectionClient(ResourceCollectionClient):
Expand Down