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,356 @@
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
+
22
+ #
23
+ """Peak Webapps service commands."""
24
+
25
+ from typing import Any, Dict, List, Optional
26
+
27
+ import typer
28
+ from peak.cli import args, helpers
29
+ from peak.helpers import combine_dictionaries, map_user_options, parse_list_of_strings, variables_to_dict
30
+ from peak.resources.webapps import Webapp
31
+ from rich.console import Console
32
+ from typing_extensions import Annotated
33
+
34
+ app = typer.Typer(
35
+ help="Visualize your data and predictions using Webapps. Please note that only generic (EKS-based) webapps are supported with CLI.",
36
+ short_help="Create and Manage Webapps.",
37
+ )
38
+
39
+ console = Console()
40
+
41
+ _WEBAPP_ID = typer.Argument(..., help="ID of the webapp to be used in this operation")
42
+
43
+ _LIST_STATUS = typer.Option(None, help="A list of webapp status to filter the list by.")
44
+
45
+ _LIST_NAME = typer.Option(None, help="Webapp name to search for")
46
+
47
+ FILE_HELP_STRING = (
48
+ "Path to the file that defines the body for this operation, supports both `yaml` file or a `jinja` template."
49
+ )
50
+
51
+ NAME = typer.Option(None, help="Name of the webapp")
52
+
53
+ DESCRIPTION = typer.Option(None, help="Description of the webapp")
54
+
55
+ TITLE = typer.Option(None, help="Title of the webapp")
56
+
57
+ IMAGE_ID = typer.Option(None, help="ID of the image to be used in this operation.")
58
+
59
+ VERSION_ID = typer.Option(
60
+ None,
61
+ help="ID of the version to be used in this operation. If version-id is not passed, webapp will be created using latest ready version of the image.",
62
+ )
63
+
64
+ MAPPING = {"imageId": "imageDetails", "versionId": "imageDetails"}
65
+
66
+
67
+ @app.command("list", short_help="List webapps.")
68
+ def list_webapps(
69
+ ctx: typer.Context,
70
+ page_size: Optional[int] = args.PAGE_SIZE,
71
+ page_number: Optional[int] = args.PAGE_NUMBER,
72
+ status: Optional[List[str]] = _LIST_STATUS,
73
+ name: Optional[str] = _LIST_NAME,
74
+ ) -> None:
75
+ """***List*** all webapps that exist for the tenant.
76
+
77
+ \b
78
+ 📝 ***Example usage:***<br/>
79
+ ```bash
80
+ peak webapps list --page-size 10 --page-number 1 --status CREATING --name test
81
+ ```
82
+
83
+ \b
84
+ 🆗 ***Response:***
85
+ ```
86
+ {
87
+ "webappsCount": 1,
88
+ "webapps": [...],
89
+ "pageCount": 1,
90
+ "pageNumber": 1,
91
+ "pageSize": 25
92
+ }
93
+ ```
94
+
95
+ 🔗 [**API Documentation**](https://service.peak.ai/webapps/api-docs/index.htm#/Webapps/list-webapp)
96
+ """
97
+ webapp_client: Webapp = ctx.obj["client"]
98
+ response = webapp_client.list_webapps(
99
+ page_size=page_size,
100
+ page_number=page_number,
101
+ return_iterator=False,
102
+ status=parse_list_of_strings(status),
103
+ name=name,
104
+ )
105
+ console.print(response)
106
+
107
+
108
+ @app.command(short_help="Create a new webapp.")
109
+ def create(
110
+ ctx: typer.Context,
111
+ file: Annotated[Optional[str], typer.Argument(..., help=FILE_HELP_STRING)] = None,
112
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
113
+ params: List[str] = args.TEMPLATE_PARAMS,
114
+ name: str = NAME,
115
+ title: str = TITLE,
116
+ description: str = DESCRIPTION,
117
+ image_id: str = IMAGE_ID,
118
+ version_id: str = VERSION_ID,
119
+ ) -> None:
120
+ """***Create*** a new webapp and start its deployment.
121
+
122
+ \b
123
+ 🧩 ***Input file schema(yaml):***<br/>
124
+ ```yaml
125
+ body (map):
126
+ name (string): Name of the webapp.
127
+ title (string | required: false): Title of the webapp.
128
+ description (string | required: false): Description of the webapp.
129
+ imageDetails (map):
130
+ imageId (number): ID of the image.
131
+ versionId (number | required: false): ID of the image version. If versionId is not passed, webapp will be created using latest ready version of the image.
132
+ ```
133
+
134
+ \b
135
+ 📝 ***Example usage:***
136
+ ```bash
137
+ peak webapps create '/path/to/file.yml' -v '/path/to/params.yml'
138
+ ```
139
+
140
+ \b
141
+ 📝 ***Example usage without yaml:***
142
+ ```bash
143
+ peak webapps create --name <name> --title <title> --description <description> --image-id <image-id> --version-id <version-id>
144
+ ```
145
+
146
+ \b
147
+ 🆗 ***Response:***
148
+ ```json
149
+ {
150
+ "id": "db88c21d-1add-45dd-a72e-8c6b83b68dee"
151
+ }
152
+ ```
153
+
154
+ 🔗 [**API Documentation**](https://service.peak.ai/webapps/api-docs/index.htm#/Webapps/create-webapp)
155
+ """
156
+ webapp_client: Webapp = ctx.obj["client"]
157
+
158
+ user_options: Dict[str, Any] = variables_to_dict(name, description, title, image_id, version_id)
159
+ user_options = map_user_options(user_options, MAPPING)
160
+
161
+ body: Dict[str, Any] = {}
162
+ if file:
163
+ body = helpers.template_handler(file=file, params_file=params_file, params=params)
164
+ body = helpers.remove_unknown_args(body, webapp_client.create_webapp)
165
+
166
+ body = combine_dictionaries(body.get("body") or {}, user_options)
167
+
168
+ response = webapp_client.create_webapp(body=body)
169
+ console.print(response)
170
+
171
+
172
+ @app.command(short_help="Update an existing webapp.")
173
+ def update(
174
+ ctx: typer.Context,
175
+ webapp_id: str = _WEBAPP_ID,
176
+ file: Annotated[Optional[str], typer.Argument(..., help=FILE_HELP_STRING)] = None,
177
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
178
+ params: List[str] = args.TEMPLATE_PARAMS,
179
+ title: str = TITLE,
180
+ description: str = DESCRIPTION,
181
+ image_id: str = IMAGE_ID,
182
+ version_id: str = VERSION_ID,
183
+ ) -> None:
184
+ """***Update*** an existing webapp.
185
+
186
+ \b
187
+ 🧩 ***Input file schema(yaml):***<br/>
188
+ ```yaml
189
+ body (map):
190
+ title (string | required: false): Title of the webapp.
191
+ description (string | required: false): Description of the webapp.
192
+ imageDetails (map | required: false):
193
+ imageId (number): ID of the image.
194
+ versionId (number | required: false): ID of the image version. If versionId is not passed, webapp will be created using latest ready version of the image.
195
+ ```
196
+
197
+ \b
198
+ 📝 ***Example usage:***
199
+ ```bash
200
+ peak webapps update "ab11c21d-1add-45dd-a72e-8c6b83b68dee" '/path/to/file.yml' -v '/path/to/params.yml'
201
+ ```
202
+
203
+ \b
204
+ 📝 ***Example usage without yaml:***
205
+ ```bash
206
+ peak webapps update "ab11c21d-1add-45dd-a72e-8c6b83b68dee" --title <title> --description <description> --image-id <image-id> --version-id <version-id>
207
+ ```
208
+
209
+ \b
210
+ 🆗 ***Response:***
211
+ ```json
212
+ {
213
+ "id": "ab11c21d-1add-45dd-a72e-8c6b83b68dee"
214
+ }
215
+ ```
216
+
217
+ 🔗 [**API Documentation**](https://service.peak.ai/webapps/api-docs/index.htm#/Webapps/update-webapp)
218
+ """
219
+ webapp_client: Webapp = ctx.obj["client"]
220
+
221
+ user_options: Dict[str, Any] = variables_to_dict(description, title, image_id, version_id)
222
+ user_options = map_user_options(user_options, MAPPING)
223
+
224
+ body: Dict[str, Any] = {}
225
+ if file:
226
+ body = helpers.template_handler(file=file, params_file=params_file, params=params)
227
+ body = helpers.remove_unknown_args(body, webapp_client.update_webapp)
228
+ body = combine_dictionaries(body.get("body") or {}, user_options)
229
+
230
+ response = webapp_client.update_webapp(webapp_id=webapp_id, body=body)
231
+ console.print(response)
232
+
233
+
234
+ @app.command(short_help="Create a new webapp or Update an existing webapp.")
235
+ def create_or_update(
236
+ ctx: typer.Context,
237
+ file: Annotated[Optional[str], typer.Argument(..., help=FILE_HELP_STRING)] = None,
238
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
239
+ params: List[str] = args.TEMPLATE_PARAMS,
240
+ name: str = NAME,
241
+ title: str = TITLE,
242
+ description: str = DESCRIPTION,
243
+ image_id: str = IMAGE_ID,
244
+ version_id: str = VERSION_ID,
245
+ ) -> None:
246
+ """***Create*** a new webapp or ***Update*** an existing webapp based on webapp name and start its deployment.
247
+
248
+ \b
249
+ 🧩 ***Input file schema(yaml):***<br/>
250
+ ```yaml
251
+ body (map):
252
+ name (string): Name of the webapp.
253
+ title (string | required: false): Title of the webapp.
254
+ description (string | required: false): Description of the webapp.
255
+ imageDetails (map):
256
+ imageId (number): ID of the image.
257
+ versionId (number | required: false): ID of the image version. If versionId is not passed, webapp will be created using latest ready version of the image.
258
+ ```
259
+
260
+ \b
261
+ 📝 ***Example usage:***
262
+ ```bash
263
+ peak webapps create-or-update '/path/to/file.yml' -v '/path/to/params.yml'
264
+ ```
265
+
266
+ \b
267
+ 📝 ***Example usage without yaml:***
268
+ ```bash
269
+ peak webapps create-or-update --name <name> --title <title> --description <description> --image-id <image-id> --version-id <version-id>
270
+ ```
271
+
272
+ \b
273
+ 🆗 ***Response:***
274
+ ```json
275
+ {
276
+ "id": "db88c21d-1add-45dd-a72e-8c6b83b68dee"
277
+ }
278
+ ```
279
+
280
+ 🔗 [**API Documentation**](https://service.peak.ai/webapps/api-docs/index.htm#/Webapps/create-webapp)
281
+ """
282
+ webapp_client: Webapp = ctx.obj["client"]
283
+
284
+ user_options: Dict[str, Any] = variables_to_dict(name, description, title, image_id, version_id)
285
+ user_options = map_user_options(user_options, MAPPING)
286
+
287
+ body: Dict[str, Any] = {}
288
+ if file:
289
+ body = helpers.template_handler(file=file, params_file=params_file, params=params)
290
+ body = helpers.remove_unknown_args(body, webapp_client.create_or_update_webapp)
291
+
292
+ body = combine_dictionaries(body.get("body") or {}, user_options)
293
+
294
+ response = webapp_client.create_or_update_webapp(body=body)
295
+ console.print(response)
296
+
297
+
298
+ @app.command(short_help="Delete an existing webapp.")
299
+ def delete(ctx: typer.Context, webapp_id: str = _WEBAPP_ID) -> None:
300
+ """***Delete*** an existing webapp.
301
+
302
+ \b
303
+ 📝 ***Example usage:***<br/>
304
+ ```bash
305
+ peak webapps delete "ab11c21d-1add-45dd-a72e-8c6b83b68dee"
306
+ ```
307
+
308
+ \b
309
+ 🆗 ***Response:***
310
+ ```json
311
+ {
312
+ "id": "ab11c21d-1add-45dd-a72e-8c6b83b68dee"
313
+ }
314
+ ```
315
+
316
+ 🔗 [**API Documentation**](https://service.peak.ai/webapps/api-docs/index.htm#/Webapps/delete-webapp)
317
+ """
318
+ webapp_client: Webapp = ctx.obj["client"]
319
+ response = webapp_client.delete_webapp(webapp_id=webapp_id)
320
+ console.print(response)
321
+
322
+
323
+ @app.command(short_help="Describe details of a webapp.")
324
+ def describe(ctx: typer.Context, webapp_id: str = _WEBAPP_ID) -> None:
325
+ """***Describe*** details for the specific webapp.
326
+
327
+ \b
328
+ 📝 ***Example usage:***<br/>
329
+ ```bash
330
+ peak webapps describe "ab11c21d-1add-45dd-a72e-8c6b83b68dee"
331
+ ```
332
+
333
+ \b
334
+ 🆗 ***Response:***
335
+ ```
336
+ {
337
+ "id": "ab11c21d-1add-45dd-a72e-8c6b83b68dee",
338
+ "name": "awesome-webapp",
339
+ "status": "AVAILABLE",
340
+ "imageDetails": {
341
+ "imageId": 1,
342
+ "versionId": 1
343
+ },
344
+ "createdAt": "2020-01-01T18:00:00.000Z",
345
+ "createdBy": "someone@peak.ai",
346
+ "updatedAt": "2020-01-01T18:00:00.000Z",
347
+ "updatedBy": "someone@peak.ai",
348
+ "tags": [...]
349
+ }
350
+ ```
351
+
352
+ 🔗 [**API Documentation**](https://service.peak.ai/webapps/api-docs/index.htm#/Webapps/get-webapp)
353
+ """
354
+ webapp_client: Webapp = ctx.obj["client"]
355
+ response = webapp_client.describe_webapp(webapp_id=webapp_id)
356
+ console.print(response)