Skip to content

Commit 19ea4ad

Browse files
authored
feat: add GET: dataset.statistics (#324)
Part of apify/apify-core#18807 - Implementation of new API endpoint `v2/datasets/{datasetId}/statistics`
1 parent 03d4b1f commit 19ea4ad

File tree

1 file changed

+42
-0
lines changed
  • src/apify_client/clients/resource_clients

1 file changed

+42
-0
lines changed

src/apify_client/clients/resource_clients/dataset.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from apify_shared.models import ListPage
88
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs
99

10+
from apify_client._errors import ApifyApiError
11+
from apify_client._utils import catch_not_found_or_throw, pluck_data
1012
from apify_client.clients.base import ResourceClient, ResourceClientAsync
1113

1214
if TYPE_CHECKING:
@@ -539,6 +541,26 @@ def push_items(self, items: JSONSerializable) -> None:
539541
json=json,
540542
)
541543

544+
def get_statistics(self) -> dict | None:
545+
"""Get the dataset statistics.
546+
547+
https://docs.apify.com/api/v2#tag/DatasetsStatistics/operation/dataset_statistics_get
548+
549+
Returns:
550+
The dataset statistics or None if the dataset does not exist.
551+
"""
552+
try:
553+
response = self.http_client.call(
554+
url=self._url('statistics'),
555+
method='GET',
556+
params=self._params(),
557+
)
558+
return pluck_data(response.json())
559+
except ApifyApiError as exc:
560+
catch_not_found_or_throw(exc)
561+
562+
return None
563+
542564

543565
class DatasetClientAsync(ResourceClientAsync):
544566
"""Async sub-client for manipulating a single dataset."""
@@ -969,3 +991,23 @@ async def push_items(self, items: JSONSerializable) -> None:
969991
data=data,
970992
json=json,
971993
)
994+
995+
async def get_statistics(self) -> dict | None:
996+
"""Get the dataset statistics.
997+
998+
https://docs.apify.com/api/v2#tag/DatasetsStatistics/operation/dataset_statistics_get
999+
1000+
Returns:
1001+
The dataset statistics or None if the dataset does not exist.
1002+
"""
1003+
try:
1004+
response = await self.http_client.call(
1005+
url=self._url('statistics'),
1006+
method='GET',
1007+
params=self._params(),
1008+
)
1009+
return pluck_data(response.json())
1010+
except ApifyApiError as exc:
1011+
catch_not_found_or_throw(exc)
1012+
1013+
return None

0 commit comments

Comments
 (0)