peak-sdk 1.16.1__py3-none-any.whl → 1.18.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- peak/_version.py +1 -1
- peak/cli/cli.py +2 -1
- peak/cli/helpers.py +1 -0
- peak/cli/metrics/metrics.py +104 -4
- peak/cli/resources/cache.py +452 -0
- peak/metrics/metrics.py +63 -3
- peak/resources/__init__.py +2 -1
- peak/resources/cache.py +650 -0
- peak/sample_yaml/metrics/publish.yaml +5 -0
- peak/sample_yaml/metrics/update-namespace.yaml +7 -0
- peak/tools/logging/logger.py +13 -6
- {peak_sdk-1.16.1.dist-info → peak_sdk-1.18.0.dist-info}/METADATA +4 -3
- {peak_sdk-1.16.1.dist-info → peak_sdk-1.18.0.dist-info}/RECORD +16 -13
- {peak_sdk-1.16.1.dist-info → peak_sdk-1.18.0.dist-info}/LICENSE +0 -0
- {peak_sdk-1.16.1.dist-info → peak_sdk-1.18.0.dist-info}/WHEEL +0 -0
- {peak_sdk-1.16.1.dist-info → peak_sdk-1.18.0.dist-info}/entry_points.txt +0 -0
peak/metrics/metrics.py
CHANGED
@@ -56,6 +56,8 @@ class Metric(BaseClient):
|
|
56
56
|
The metrics can be published either by passing artifact and namespace,
|
57
57
|
or by passing collection_id and namespace. If both artifact and collection_id
|
58
58
|
are provided, artifact takes priority. If the namespace is not provided, the 'default' namespace is used.
|
59
|
+
You can optionally include `namespaceMetadata` and `namespaceDescription` in the body
|
60
|
+
to provide additional context about the namespace.
|
59
61
|
|
60
62
|
REFERENCE:
|
61
63
|
🔗 `API Documentation <https://service.peak.ai/semantic-layer/api-docs/index.htm#/Metrics/post_api_v1_metrics>`__
|
@@ -74,6 +76,8 @@ class Metric(BaseClient):
|
|
74
76
|
|
75
77
|
{
|
76
78
|
"namespace": "string",
|
79
|
+
"namespaceMetadata": { "key": "value" },
|
80
|
+
"namespaceDescription": "Optional description"
|
77
81
|
}
|
78
82
|
|
79
83
|
Raises:
|
@@ -84,10 +88,12 @@ class Metric(BaseClient):
|
|
84
88
|
UnprocessableEntityException: The server was unable to process the request.
|
85
89
|
InternalServerErrorException: The server failed to process the request.
|
86
90
|
"""
|
91
|
+
if body and "namespaceMetadata" in body:
|
92
|
+
body["namespaceMetadata"] = json.dumps(body["namespaceMetadata"])
|
93
|
+
|
87
94
|
if artifact:
|
88
95
|
method, endpoint = HttpMethods.POST, f"{self.BASE_ENDPOINT}/metrics"
|
89
96
|
path = self.__get_artifact_details(artifact)
|
90
|
-
|
91
97
|
return self.session.create_request( # type: ignore[no-any-return]
|
92
98
|
endpoint,
|
93
99
|
method,
|
@@ -111,7 +117,7 @@ class Metric(BaseClient):
|
|
111
117
|
|
112
118
|
def query(
|
113
119
|
self,
|
114
|
-
measures: List[str],
|
120
|
+
measures: Optional[List[str]] = None,
|
115
121
|
namespace: Optional[str] = None,
|
116
122
|
generate_sql: Optional[bool] = False, # noqa: FBT002
|
117
123
|
dimensions: Optional[List[str]] = None,
|
@@ -128,7 +134,7 @@ class Metric(BaseClient):
|
|
128
134
|
🔗 `API Documentation <https://service.peak.ai/semantic-layer/api-docs/index.htm#/Query/get_api_v1_metrics_query>`__
|
129
135
|
|
130
136
|
Args:
|
131
|
-
measures (List[str]): An array of measures to include in the query. Measures represent quantitative metrics such as sums or counts.
|
137
|
+
measures (List[str] | None): An array of measures to include in the query. Measures represent quantitative metrics such as sums or counts.
|
132
138
|
namespace (str | None): The namespace associated with the metrics. If not provided, the default namespace is used.
|
133
139
|
generate_sql (bool | None): Indicates whether to return the SQL query instead of data. If `true`, the response will include the SQL query used to retrieve the metrics. Default is `false`.
|
134
140
|
dimensions (List[str] | None): An array of dimensions to include in the query. Dimensions represent qualitative categories such as time, location, or product names.
|
@@ -183,7 +189,9 @@ class Metric(BaseClient):
|
|
183
189
|
self,
|
184
190
|
page_size: Optional[int] = None,
|
185
191
|
page_number: Optional[int] = None,
|
192
|
+
publication_id: Optional[str] = None,
|
186
193
|
namespace: Optional[str] = None,
|
194
|
+
search_term: Optional[str] = None,
|
187
195
|
type: Optional[str] = None, # noqa: A002
|
188
196
|
*,
|
189
197
|
return_iterator: Literal[False],
|
@@ -194,7 +202,9 @@ class Metric(BaseClient):
|
|
194
202
|
self,
|
195
203
|
page_size: Optional[int] = None,
|
196
204
|
page_number: Optional[int] = None,
|
205
|
+
publication_id: Optional[str] = None,
|
197
206
|
namespace: Optional[str] = None,
|
207
|
+
search_term: Optional[str] = None,
|
198
208
|
type: Optional[str] = None, # noqa: A002
|
199
209
|
*,
|
200
210
|
return_iterator: Literal[True] = True,
|
@@ -204,7 +214,9 @@ class Metric(BaseClient):
|
|
204
214
|
self,
|
205
215
|
page_size: Optional[int] = None,
|
206
216
|
page_number: Optional[int] = None,
|
217
|
+
publication_id: Optional[str] = None,
|
207
218
|
namespace: Optional[str] = None,
|
219
|
+
search_term: Optional[str] = None,
|
208
220
|
type: Optional[str] = None, # noqa: A002
|
209
221
|
*,
|
210
222
|
return_iterator: bool = True,
|
@@ -217,7 +229,9 @@ class Metric(BaseClient):
|
|
217
229
|
Args:
|
218
230
|
page_size (int | None): The number of images per page.
|
219
231
|
page_number (int | None): The page number to retrieve. Only used when `return_iterator` is False.
|
232
|
+
publication_id (str | None): The publication ID to retrieve metrics from. If not provided, all metrics are retrieved.
|
220
233
|
namespace (str | None): The namespace associated with the metrics. If not provided, the default namespace is used.
|
234
|
+
search_term (str | None): The search term to filter the metrics by. If not provided, all metrics are retrieved.
|
221
235
|
type (str | None): The type of metrics to retrieve. If not provided, all metrics are retrieved. Available types are `cube`, `view`, `dimension`, `measure`, `segment` and `all`.
|
222
236
|
return_iterator (bool): Whether to return an iterator object or list of metrics for a specified page number, defaults to True.
|
223
237
|
|
@@ -236,7 +250,9 @@ class Metric(BaseClient):
|
|
236
250
|
method, endpoint = HttpMethods.GET, f"{self.BASE_ENDPOINT}/metrics"
|
237
251
|
params = {
|
238
252
|
"pageSize": page_size,
|
253
|
+
"publicationId": publication_id,
|
239
254
|
"namespace": namespace,
|
255
|
+
"searchTerm": search_term,
|
240
256
|
"type": type,
|
241
257
|
}
|
242
258
|
|
@@ -537,6 +553,50 @@ class Metric(BaseClient):
|
|
537
553
|
params={**params, "pageNumber": page_number},
|
538
554
|
)
|
539
555
|
|
556
|
+
def update_namespace(
|
557
|
+
self,
|
558
|
+
namespace: str,
|
559
|
+
description: Optional[str] = None,
|
560
|
+
metadata: Optional[Dict[str, Any]] = None,
|
561
|
+
) -> Dict[str, Any]:
|
562
|
+
"""Update a namespace with a new description and metadata.
|
563
|
+
|
564
|
+
REFERENCE:
|
565
|
+
🔗 `API Documentation <https://service.peak.ai/semantic-layer/api-docs/index.htm#/Namespaces/patch_api_v1_namespaces__namespace_>`__
|
566
|
+
|
567
|
+
Args:
|
568
|
+
namespace (str): The name of the namespace to update.
|
569
|
+
description (str | None): The new description for the namespace.
|
570
|
+
metadata (Dict[str, Any] | None): The new metadata for the namespace.
|
571
|
+
|
572
|
+
Returns:
|
573
|
+
Dict[str, Any]: A dictionary containing details about the updated namespace.
|
574
|
+
|
575
|
+
Raises:
|
576
|
+
InvalidParameterException: The given request parameters are invalid.
|
577
|
+
UnauthorizedException: The credentials are invalid.
|
578
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
579
|
+
NotFoundException: The given namespace does not exist.
|
580
|
+
UnprocessableEntityException: The server was unable to process the request.
|
581
|
+
InternalServerErrorException: The server failed to process the request.
|
582
|
+
"""
|
583
|
+
if not namespace:
|
584
|
+
raise InvalidParameterException(message="Namespace must be provided.")
|
585
|
+
|
586
|
+
method, endpoint = HttpMethods.PATCH, f"{self.BASE_ENDPOINT}/namespaces/{namespace}"
|
587
|
+
body = {}
|
588
|
+
if description is not None:
|
589
|
+
body["description"] = description
|
590
|
+
if metadata is not None:
|
591
|
+
body["metadata"] = json.dumps(metadata)
|
592
|
+
|
593
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
594
|
+
endpoint,
|
595
|
+
method,
|
596
|
+
content_type=ContentType.APPLICATION_JSON,
|
597
|
+
body=body,
|
598
|
+
)
|
599
|
+
|
540
600
|
|
541
601
|
def get_client(session: Optional[Session] = None) -> Metric:
|
542
602
|
"""Returns a Metrics client, If no session is provided, a default session is used.
|
peak/resources/__init__.py
CHANGED
@@ -24,11 +24,12 @@ from __future__ import annotations
|
|
24
24
|
|
25
25
|
from typing import List
|
26
26
|
|
27
|
-
from peak.resources import alerts, artifacts, images, services, tenants, users, webapps, workflows
|
27
|
+
from peak.resources import alerts, artifacts, cache, images, services, tenants, users, webapps, workflows
|
28
28
|
|
29
29
|
__all__: List[str] = [
|
30
30
|
"alerts",
|
31
31
|
"artifacts",
|
32
|
+
"cache",
|
32
33
|
"images",
|
33
34
|
"services",
|
34
35
|
"tenants",
|