|
7 | 7 | from apify_shared.models import ListPage
|
8 | 8 | from apify_shared.utils import filter_out_none_values_recursively, ignore_docs
|
9 | 9 |
|
| 10 | +from apify_client._errors import ApifyApiError |
| 11 | +from apify_client._utils import catch_not_found_or_throw, pluck_data |
10 | 12 | from apify_client.clients.base import ResourceClient, ResourceClientAsync
|
11 | 13 |
|
12 | 14 | if TYPE_CHECKING:
|
@@ -539,6 +541,26 @@ def push_items(self, items: JSONSerializable) -> None:
|
539 | 541 | json=json,
|
540 | 542 | )
|
541 | 543 |
|
| 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 | + |
542 | 564 |
|
543 | 565 | class DatasetClientAsync(ResourceClientAsync):
|
544 | 566 | """Async sub-client for manipulating a single dataset."""
|
@@ -969,3 +991,23 @@ async def push_items(self, items: JSONSerializable) -> None:
|
969 | 991 | data=data,
|
970 | 992 | json=json,
|
971 | 993 | )
|
| 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