-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathlimits.py
More file actions
99 lines (73 loc) · 3.87 KB
/
Copy pathlimits.py
File metadata and controls
99 lines (73 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from __future__ import annotations
from typing import TYPE_CHECKING
from cognite.client._api_client import APIClient
from cognite.client.constants import DEFAULT_LIMIT_READ
from cognite.client.data_classes.limits import Limit, LimitList
from cognite.client.utils._experimental import FeaturePreviewWarning
from cognite.client.utils._identifier import LimitId
if TYPE_CHECKING:
from cognite.client import AsyncCogniteClient
from cognite.client.config import ClientConfig
from cognite.client.data_classes.filters import Prefix
class LimitsAPI(APIClient):
_RESOURCE_PATH = "/limits/values"
def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: AsyncCogniteClient) -> None:
super().__init__(config, api_version, cognite_client)
self._warning = FeaturePreviewWarning(
api_maturity="alpha",
sdk_maturity="alpha",
feature_name="Limits API",
)
async def retrieve(self, id: str) -> Limit | None:
"""`Retrieve a limit value by its id <https://api-docs.cognite.com/20230101-alpha/tag/Limits/operation/fetchLimitById/>`_.
Retrieves a limit value by its `limitId`.
Args:
id (str): Limit ID to retrieve.
Limits are identified by an id containing the service name and a service-scoped limit name.
For instance `atlas.monthly_ai_tokens` is the id of the `atlas` service limit `monthly_ai_tokens`.
Service and limit names are always in `lower_snake_case`.
Returns:
Limit | None: The requested limit, or `None` if not found.
Examples:
Retrieve a single limit by id:
>>> from cognite.client import CogniteClient, AsyncCogniteClient
>>> client = CogniteClient()
>>> # async_client = AsyncCogniteClient() # another option
>>> res = client.limits.retrieve(id="atlas.monthly_ai_tokens")
"""
self._warning.warn()
headers = {"cdf-version": f"{self._config.api_subversion}-alpha"}
return await self._retrieve(
identifier=LimitId(id),
cls=Limit,
headers=headers,
)
async def list(self, filter: Prefix | None = None, limit: int | None = DEFAULT_LIMIT_READ) -> LimitList:
"""`List all limit values <https://api-docs.cognite.com/20230101-alpha/tag/Limits/operation/listLimits/>`_.
Retrieves all limit values for a specific project. Optionally filter by limit ID prefix using a `Prefix` filter.
Args:
filter (Prefix | None): Optional `Prefix` filter to apply on the `limitId` property (only `Prefix` filters are supported).
limit (int | None): Maximum number of limits to return. Defaults to 25. Set to None or -1 to return all limits
Returns:
LimitList: List of all limit values in the project.
Examples:
List all limits:
>>> from cognite.client import CogniteClient, AsyncCogniteClient
>>> client = CogniteClient()
>>> # async_client = AsyncCogniteClient() # another option
>>> limits = client.limits.list(limit=None)
List limits filtered by prefix (e.g., all limits for the 'atlas' service):
>>> from cognite.client.data_classes.filters import Prefix
>>> prefix_filter = Prefix("limitId", "atlas.")
>>> limits = client.limits.list(filter=prefix_filter)
"""
self._warning.warn()
headers = {"cdf-version": f"{self._config.api_subversion}-alpha"}
return await self._list(
method="GET" if filter is None else "POST",
list_cls=LimitList,
resource_cls=Limit,
limit=limit,
filter=None if filter is None else filter.dump(camel_case_property=True),
headers=headers,
)