peak-sdk 1.0.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.
Files changed (51) hide show
  1. peak/__init__.py +36 -0
  2. peak/_version.py +21 -0
  3. peak/auth.py +22 -0
  4. peak/base_client.py +52 -0
  5. peak/cli/__init_.py +20 -0
  6. peak/cli/args.py +84 -0
  7. peak/cli/cli.py +56 -0
  8. peak/cli/helpers.py +187 -0
  9. peak/cli/press/__init__.py +21 -0
  10. peak/cli/press/apps/__init__.py +40 -0
  11. peak/cli/press/apps/deployments.py +238 -0
  12. peak/cli/press/apps/specs.py +387 -0
  13. peak/cli/press/blocks/__init__.py +40 -0
  14. peak/cli/press/blocks/deployments.py +240 -0
  15. peak/cli/press/blocks/specs.py +492 -0
  16. peak/cli/press/deployments.py +78 -0
  17. peak/cli/press/specs.py +131 -0
  18. peak/cli/resources/__init__.py +21 -0
  19. peak/cli/resources/artifacts.py +310 -0
  20. peak/cli/resources/images.py +886 -0
  21. peak/cli/resources/webapps.py +356 -0
  22. peak/cli/resources/workflows.py +703 -0
  23. peak/cli/ruff.toml +11 -0
  24. peak/cli/version.py +49 -0
  25. peak/compression.py +162 -0
  26. peak/config.py +24 -0
  27. peak/constants.py +105 -0
  28. peak/exceptions.py +217 -0
  29. peak/handler.py +358 -0
  30. peak/helpers.py +184 -0
  31. peak/logger.py +48 -0
  32. peak/press/__init__.py +28 -0
  33. peak/press/apps.py +669 -0
  34. peak/press/blocks.py +707 -0
  35. peak/press/deployments.py +145 -0
  36. peak/press/specs.py +260 -0
  37. peak/py.typed +0 -0
  38. peak/resources/__init__.py +28 -0
  39. peak/resources/artifacts.py +343 -0
  40. peak/resources/images.py +675 -0
  41. peak/resources/webapps.py +278 -0
  42. peak/resources/workflows.py +625 -0
  43. peak/session.py +259 -0
  44. peak/telemetry.py +201 -0
  45. peak/template.py +231 -0
  46. peak/validators.py +48 -0
  47. peak_sdk-1.0.0.dist-info/LICENSE +201 -0
  48. peak_sdk-1.0.0.dist-info/METADATA +199 -0
  49. peak_sdk-1.0.0.dist-info/RECORD +51 -0
  50. peak_sdk-1.0.0.dist-info/WHEEL +4 -0
  51. peak_sdk-1.0.0.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,145 @@
1
+ #
2
+ # # Copyright © 2023 Peak AI Limited. or its affiliates. All Rights Reserved.
3
+ # #
4
+ # # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # # may not use this file except in compliance with the License. A copy of
6
+ # # the License is located at:
7
+ # #
8
+ # # https://github.com/PeakBI/peak-sdk/blob/main/LICENSE
9
+ # #
10
+ # # or in the "license" file accompanying this file. This file is
11
+ # # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # # ANY KIND, either express or implied. See the License for the specific
13
+ # # language governing permissions and limitations under the License.
14
+ # #
15
+ # # This file is part of the peak-sdk.
16
+ # # see (https://github.com/PeakBI/peak-sdk)
17
+ # #
18
+ # # You should have received a copy of the APACHE LICENSE, VERSION 2.0
19
+ # # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
20
+ #
21
+ """Deployments client module."""
22
+ from __future__ import annotations
23
+
24
+ from typing import Any, Dict, Iterator, List, Literal, Optional, overload
25
+
26
+ from peak.base_client import BaseClient
27
+ from peak.constants import ContentType, HttpMethods
28
+ from peak.session import Session
29
+
30
+
31
+ class Deployment(BaseClient):
32
+ """Client class for interacting with Deployments."""
33
+
34
+ BASE_ENDPOINT = "v1/deployments"
35
+
36
+ @overload
37
+ def list_deployments(
38
+ self,
39
+ status: Optional[List[str]] = None,
40
+ kind: Optional[str] = None,
41
+ term: Optional[str] = None,
42
+ sort: Optional[List[str]] = None,
43
+ page_size: Optional[int] = None,
44
+ page_number: Optional[int] = None,
45
+ *,
46
+ return_iterator: Literal[False],
47
+ ) -> Dict[str, Any]:
48
+ ...
49
+
50
+ @overload
51
+ def list_deployments(
52
+ self,
53
+ status: Optional[List[str]] = None,
54
+ kind: Optional[str] = None,
55
+ term: Optional[str] = None,
56
+ sort: Optional[List[str]] = None,
57
+ page_size: Optional[int] = None,
58
+ page_number: Optional[int] = None,
59
+ *,
60
+ return_iterator: Literal[True] = True,
61
+ ) -> Iterator[Dict[str, Any]]:
62
+ ...
63
+
64
+ def list_deployments(
65
+ self,
66
+ status: Optional[List[str]] = None,
67
+ kind: Optional[str] = None,
68
+ term: Optional[str] = None,
69
+ sort: Optional[List[str]] = None,
70
+ page_size: Optional[int] = None,
71
+ page_number: Optional[int] = None,
72
+ *,
73
+ return_iterator: bool = True,
74
+ ) -> Iterator[Dict[str, Any]] | Dict[str, Any]:
75
+ """List all App & Block Deployments ordered by creation date. Returns info on the latest revision of each deployment.
76
+
77
+ REFERENCE:
78
+ 🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/Deployments/get_v1_deployments>`__
79
+
80
+ Args:
81
+ status (List[str] | None): List of statuses to filter deployments.
82
+ kind (str | None): Return deployments of the kind specified.
83
+ term (str | None): Return deployments containing the specified term in name, title, description and summary.
84
+ sort (List[str] | None): List of fields with desired ordering in the format `[<field>:<order>, ...]`,
85
+ where `order` is one of `['asc', 'desc']` and field is an ordered parameter within the response,
86
+ defaults to `[]`. Valid fields are `createdAt`, `createdBy`, `name` and `title`.
87
+ page_size (int | None): Number of deployments to include per page.
88
+ page_number (int | None): The page number to retrieve. Only used when `return_iterator` is False.
89
+ return_iterator (bool): Whether to return an iterator object or list of deployments for a specified page number, defaults to True.
90
+
91
+ Returns:
92
+ Iterator[Dict[str, Any]] | Dict[str, Any]: An iterator object which returns an element per iteration, until there are no more elements to return.
93
+ If `return_iterator` is set to False, a dictionary containing the list and pagination details is returned instead.
94
+
95
+ Set `return_iterator` to True if you want automatic client-side pagination, or False if you want server-side pagination.
96
+
97
+ Raises:
98
+ BadRequestException: The given parameters are invalid.
99
+ UnauthorizedException: The credentials are invalid.
100
+ ForbiddenException: The user does not have permission to perform the operation.
101
+ InternalServerErrorException: The server encountered an unexpected condition that
102
+ prevented it from fulfilling the request.
103
+ StopIteration: There are no more pages to list.
104
+ """
105
+ method, endpoint = HttpMethods.GET, f"{self.BASE_ENDPOINT}/"
106
+ params: Dict[str, Any] = {
107
+ "status": status,
108
+ "kind": kind,
109
+ "term": term,
110
+ "sort": sort,
111
+ "pageSize": page_size,
112
+ }
113
+
114
+ if return_iterator:
115
+ return self.session.create_generator_request(
116
+ endpoint,
117
+ method,
118
+ content_type=ContentType.APPLICATION_JSON,
119
+ response_key="deployments",
120
+ params=params,
121
+ subdomain="press",
122
+ )
123
+
124
+ return self.session.create_request( # type: ignore[no-any-return]
125
+ endpoint,
126
+ method,
127
+ content_type=ContentType.APPLICATION_JSON,
128
+ params={**params, "pageNumber": page_number},
129
+ subdomain="press",
130
+ )
131
+
132
+
133
+ def get_client(session: Optional[Session] = None) -> Deployment:
134
+ """Returns a Deployment client.
135
+
136
+ Args:
137
+ session (Optional[Session]): A Session Object. If no session is provided, a default session is used.
138
+
139
+ Returns:
140
+ Deployment: the Deployment client object
141
+ """
142
+ return Deployment(session)
143
+
144
+
145
+ __all__: List[str] = ["get_client"]
peak/press/specs.py ADDED
@@ -0,0 +1,260 @@
1
+ #
2
+ # # Copyright © 2023 Peak AI Limited. or its affiliates. All Rights Reserved.
3
+ # #
4
+ # # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # # may not use this file except in compliance with the License. A copy of
6
+ # # the License is located at:
7
+ # #
8
+ # # https://github.com/PeakBI/peak-sdk/blob/main/LICENSE
9
+ # #
10
+ # # or in the "license" file accompanying this file. This file is
11
+ # # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # # ANY KIND, either express or implied. See the License for the specific
13
+ # # language governing permissions and limitations under the License.
14
+ # #
15
+ # # This file is part of the peak-sdk.
16
+ # # see (https://github.com/PeakBI/peak-sdk)
17
+ # #
18
+ # # You should have received a copy of the APACHE LICENSE, VERSION 2.0
19
+ # # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
20
+ #
21
+ """Specs client module."""
22
+ from __future__ import annotations
23
+
24
+ from typing import Any, Dict, Iterator, List, Literal, Optional, overload
25
+
26
+ from peak.base_client import BaseClient
27
+ from peak.constants import ContentType, HttpMethods
28
+ from peak.session import Session
29
+
30
+
31
+ class Spec(BaseClient):
32
+ """Client class for interacting with Specs."""
33
+
34
+ BASE_ENDPOINT = "v1/specs"
35
+
36
+ @overload
37
+ def list_specs(
38
+ self,
39
+ status: Optional[List[str]] = None,
40
+ featured: Optional[bool] = None,
41
+ kind: Optional[str] = None,
42
+ term: Optional[str] = None,
43
+ sort: Optional[List[str]] = None,
44
+ scope: Optional[List[str]] = None,
45
+ page_size: Optional[int] = None,
46
+ page_number: Optional[int] = None,
47
+ *,
48
+ return_iterator: Literal[False],
49
+ ) -> Dict[str, Any]:
50
+ ...
51
+
52
+ @overload
53
+ def list_specs(
54
+ self,
55
+ status: Optional[List[str]] = None,
56
+ featured: Optional[bool] = None,
57
+ kind: Optional[str] = None,
58
+ term: Optional[str] = None,
59
+ sort: Optional[List[str]] = None,
60
+ scope: Optional[List[str]] = None,
61
+ page_size: Optional[int] = None,
62
+ page_number: Optional[int] = None,
63
+ *,
64
+ return_iterator: Literal[True] = True,
65
+ ) -> Iterator[Dict[str, Any]]:
66
+ ...
67
+
68
+ def list_specs(
69
+ self,
70
+ status: Optional[List[str]] = None,
71
+ featured: Optional[bool] = None,
72
+ kind: Optional[str] = None,
73
+ term: Optional[str] = None,
74
+ sort: Optional[List[str]] = None,
75
+ scope: Optional[List[str]] = None,
76
+ page_size: Optional[int] = None,
77
+ page_number: Optional[int] = None,
78
+ *,
79
+ return_iterator: bool = True,
80
+ ) -> Iterator[Dict[str, Any]] | Dict[str, Any]:
81
+ """List all published App & Block Specs ordered by creation date. Returns info on the latest release of each spec.
82
+
83
+ REFERENCE:
84
+ 🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/Specs/get_v1_specs>`__
85
+
86
+ Args:
87
+ status (List[str] | None): List of statuses to filter specs.
88
+ featured (bool | None): Whether to only return featured specs.
89
+ kind (str | None): Return specs of the kind specified.
90
+ term (str | None): Return specs containing the specified term in name, title, description and summary.
91
+ sort (List[str] | None): List of fields with desired ordering in the format `[<field>:<order>, ...]`,
92
+ where `order` is one of `['asc', 'desc']` and field is an ordered parameter within the response,
93
+ defaults to `[]`. Valid fields are `createdAt`, `createdBy`, `name` and `title`.
94
+ scope (List[str] | None): List of scopes to only return specs of those scopes. Valid values are `private`, `public` and `shared`.
95
+ page_size (int | None): Number of specs to include per page.
96
+ page_number (int | None): The page number to retrieve. Only used when `return_iterator` is False.
97
+ return_iterator (bool): Whether to return an iterator object or list of specs for a specified page number, defaults to True.
98
+
99
+ Returns:
100
+ Iterator[Dict[str, Any]] | Dict[str, Any]: An iterator object which returns an element per iteration, until there are no more elements to return.
101
+ If `return_iterator` is set to False, a dictionary containing the list and pagination details is returned instead.
102
+
103
+ Set `return_iterator` to True if you want automatic client-side pagination, or False if you want server-side pagination.
104
+
105
+ Raises:
106
+ BadRequestException: The given parameters are invalid.
107
+ UnauthorizedException: The credentials are invalid.
108
+ ForbiddenException: The user does not have permission to perform the operation.
109
+ InternalServerErrorException: The server encountered an unexpected condition that
110
+ prevented it from fulfilling the request.
111
+ StopIteration: There are no more pages to list.
112
+ """
113
+ method, endpoint = HttpMethods.GET, f"{self.BASE_ENDPOINT}/"
114
+ params: Dict[str, Any] = {
115
+ "status": status,
116
+ "featured": featured,
117
+ "kind": kind,
118
+ "term": term,
119
+ "sort": sort,
120
+ "scope": scope,
121
+ "pageSize": page_size,
122
+ }
123
+
124
+ if return_iterator:
125
+ return self.session.create_generator_request(
126
+ endpoint,
127
+ method,
128
+ content_type=ContentType.APPLICATION_JSON,
129
+ response_key="specs",
130
+ params=params,
131
+ subdomain="press",
132
+ )
133
+
134
+ return self.session.create_request( # type: ignore[no-any-return]
135
+ endpoint,
136
+ method,
137
+ content_type=ContentType.APPLICATION_JSON,
138
+ params={**params, "pageNumber": page_number},
139
+ subdomain="press",
140
+ )
141
+
142
+ @overload
143
+ def list_spec_release_deployments(
144
+ self,
145
+ spec_id: str,
146
+ version: str,
147
+ status: Optional[List[str]] = None,
148
+ name: Optional[str] = None,
149
+ title: Optional[str] = None,
150
+ sort: Optional[List[str]] = None,
151
+ page_size: Optional[int] = None,
152
+ page_number: Optional[int] = None,
153
+ *,
154
+ return_iterator: Literal[False],
155
+ ) -> Dict[str, Any]:
156
+ ...
157
+
158
+ @overload
159
+ def list_spec_release_deployments(
160
+ self,
161
+ spec_id: str,
162
+ version: str,
163
+ status: Optional[List[str]] = None,
164
+ name: Optional[str] = None,
165
+ title: Optional[str] = None,
166
+ sort: Optional[List[str]] = None,
167
+ page_size: Optional[int] = None,
168
+ page_number: Optional[int] = None,
169
+ *,
170
+ return_iterator: Literal[True] = True,
171
+ ) -> Iterator[Dict[str, Any]]:
172
+ ...
173
+
174
+ def list_spec_release_deployments(
175
+ self,
176
+ spec_id: str,
177
+ version: str,
178
+ status: Optional[List[str]] = None,
179
+ name: Optional[str] = None,
180
+ title: Optional[str] = None,
181
+ sort: Optional[List[str]] = None,
182
+ page_size: Optional[int] = None,
183
+ page_number: Optional[int] = None,
184
+ *,
185
+ return_iterator: bool = True,
186
+ ) -> Iterator[Dict[str, Any]] | Dict[str, Any]:
187
+ """Get all deployments of a App or Block spec release (ordered by most recently created to oldest).
188
+
189
+ REFERENCE:
190
+ 🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/Specs/get_v1_specs__specId__releases__release__deployments>`__
191
+
192
+ Args:
193
+ spec_id (str): The ID of the App or Block spec.
194
+ version (str): The release version of the spec in valid semantic versioning format.
195
+ status (List[str] | None): List of statuses to filter deployments.
196
+ name (str | None): String to filter deployments by name.
197
+ title (str | None): String to filter deployments by title.
198
+ sort (List[str] | None): List of fields with desired ordering in the format `[<field>:<order>, ...]`,
199
+ where `order` is one of `['asc', 'desc']` and field is an ordered parameter within the response.
200
+ Valid fields are `createdAt`, `createdBy` and `name`.
201
+ page_size (int | None): Number of specs to include per page.
202
+ page_number (int | None): The page number to retrieve. Only used when `return_iterator` is False.
203
+ return_iterator (bool): Whether to return an iterator object or list of specs for a specified page number, defaults to True.
204
+
205
+ Returns:
206
+ Iterator[Dict[str, Any] | Dict[str, Any]: an iterator object which returns an element per iteration, until there are no more elements to return.
207
+ If `return_iterator` is set to False, a dictionary containing the list and pagination details is returned instead.
208
+
209
+ Set `return_iterator` to True if you want automatic client-side pagination, or False if you want server-side pagination.
210
+
211
+ Raises:
212
+ BadRequestException: The given parameters are invalid.
213
+ UnauthorizedException: The credentials are invalid.
214
+ ForbiddenException: The user does not have permission to perform the operation.
215
+ NotFoundException: The given spec does not exist.
216
+ InternalServerErrorException: the server encountered an unexpected condition that
217
+ prevented it from fulfilling the request.
218
+ """
219
+ method, endpoint = HttpMethods.GET, f"{self.BASE_ENDPOINT}/{spec_id}/releases/{version}/deployments"
220
+
221
+ params: Dict[str, Any] = {
222
+ "status": status,
223
+ "name": name,
224
+ "title": title,
225
+ "sort": sort,
226
+ "pageSize": page_size,
227
+ }
228
+
229
+ if return_iterator:
230
+ return self.session.create_generator_request(
231
+ endpoint,
232
+ method,
233
+ content_type=ContentType.APPLICATION_JSON,
234
+ response_key="deployments",
235
+ params=params,
236
+ subdomain="press",
237
+ )
238
+
239
+ return self.session.create_request( # type: ignore[no-any-return]
240
+ endpoint,
241
+ method,
242
+ content_type=ContentType.APPLICATION_JSON,
243
+ params={**params, "pageNumber": page_number},
244
+ subdomain="press",
245
+ )
246
+
247
+
248
+ def get_client(session: Optional[Session] = None) -> Spec:
249
+ """Returns a Spec client.
250
+
251
+ Args:
252
+ session (Optional[Session]): A Session Object. If no session is provided, a default session is used.
253
+
254
+ Returns:
255
+ Spec: the Spec client object
256
+ """
257
+ return Spec(session)
258
+
259
+
260
+ __all__: List[str] = ["get_client"]
peak/py.typed ADDED
File without changes
@@ -0,0 +1,28 @@
1
+ #
2
+ # # Copyright © 2023 Peak AI Limited. or its affiliates. All Rights Reserved.
3
+ # #
4
+ # # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # # may not use this file except in compliance with the License. A copy of
6
+ # # the License is located at:
7
+ # #
8
+ # # https://github.com/PeakBI/peak-sdk/blob/main/LICENSE
9
+ # #
10
+ # # or in the "license" file accompanying this file. This file is
11
+ # # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # # ANY KIND, either express or implied. See the License for the specific
13
+ # # language governing permissions and limitations under the License.
14
+ # #
15
+ # # This file is part of the peak-sdk.
16
+ # # see (https://github.com/PeakBI/peak-sdk)
17
+ # #
18
+ # # You should have received a copy of the APACHE LICENSE, VERSION 2.0
19
+ # # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
20
+ #
21
+ """This module exports all platform resources from the `Peak-Platform`."""
22
+ from __future__ import annotations
23
+
24
+ from typing import List
25
+
26
+ from peak.resources import artifacts, images, webapps, workflows
27
+
28
+ __all__: List[str] = ["workflows", "images", "artifacts", "webapps"]