Skip to content
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

feat: add GET: dataset.statistics #324

Merged
merged 1 commit into from
Jan 7, 2025
Merged
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
42 changes: 42 additions & 0 deletions src/apify_client/clients/resource_clients/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from apify_shared.models import ListPage
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs

from apify_client._errors import ApifyApiError
from apify_client._utils import catch_not_found_or_throw, pluck_data
from apify_client.clients.base import ResourceClient, ResourceClientAsync

if TYPE_CHECKING:
Expand Down Expand Up @@ -539,6 +541,26 @@ def push_items(self, items: JSONSerializable) -> None:
json=json,
)

def get_statistics(self) -> dict | None:
"""Get the dataset statistics.

https://docs.apify.com/api/v2#tag/DatasetsStatistics/operation/dataset_statistics_get

Returns:
The dataset statistics or None if the dataset does not exist.
"""
try:
response = self.http_client.call(
url=self._url('statistics'),
method='GET',
params=self._params(),
)
return pluck_data(response.json())
except ApifyApiError as exc:
catch_not_found_or_throw(exc)

return None


class DatasetClientAsync(ResourceClientAsync):
"""Async sub-client for manipulating a single dataset."""
Expand Down Expand Up @@ -969,3 +991,23 @@ async def push_items(self, items: JSONSerializable) -> None:
data=data,
json=json,
)

async def get_statistics(self) -> dict | None:
"""Get the dataset statistics.

https://docs.apify.com/api/v2#tag/DatasetsStatistics/operation/dataset_statistics_get

Returns:
The dataset statistics or None if the dataset does not exist.
"""
try:
response = await self.http_client.call(
url=self._url('statistics'),
method='GET',
params=self._params(),
)
return pluck_data(response.json())
except ApifyApiError as exc:
catch_not_found_or_throw(exc)

return None
Loading