craft-ai-sdk 0.50.1rc2__tar.gz → 0.51.0rc1__tar.gz

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.

Potentially problematic release.


This version of craft-ai-sdk might be problematic. Click here for more details.

Files changed (23) hide show
  1. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/PKG-INFO +1 -1
  2. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/__init__.py +1 -1
  3. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/core/pipelines.py +46 -1
  4. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/core/steps.py +70 -21
  5. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/sdk.py +3 -1
  6. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/documentation.pdf +0 -0
  7. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/pyproject.toml +1 -1
  8. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/setup.py +1 -1
  9. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/LICENSE +0 -0
  10. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/README.md +0 -0
  11. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/constants.py +0 -0
  12. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/core/data_store.py +0 -0
  13. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/core/deployments.py +0 -0
  14. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/core/endpoints.py +0 -0
  15. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/core/environment_variables.py +0 -0
  16. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/core/pipeline_executions.py +0 -0
  17. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/core/pipeline_metrics.py +0 -0
  18. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/core/resource_metrics.py +0 -0
  19. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/core/users.py +0 -0
  20. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/exceptions.py +0 -0
  21. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/io.py +0 -0
  22. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/utils.py +0 -0
  23. {craft_ai_sdk-0.50.1rc2 → craft_ai_sdk-0.51.0rc1}/craft_ai_sdk/warnings.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: craft-ai-sdk
3
- Version: 0.50.1rc2
3
+ Version: 0.51.0rc1
4
4
  Summary: Craft AI MLOps platform SDK
5
5
  Home-page: https://www.craft.ai/
6
6
  License: Apache-2.0
@@ -14,4 +14,4 @@ from .io import ( # noqa: F401
14
14
  )
15
15
 
16
16
 
17
- __version__ = "0.50.1rc2"
17
+ __version__ = "0.51.0rc1"
@@ -10,6 +10,7 @@ from ..utils import (
10
10
  multipartify,
11
11
  handle_data_store_response,
12
12
  remove_keys_from_dict,
13
+ _datetime_to_timestamp_in_ms,
13
14
  )
14
15
  from .steps import (
15
16
  _add_inputs_outputs_in_message,
@@ -219,7 +220,7 @@ def create_pipeline(
219
220
  outputs,
220
221
  pipeline_name=pipeline_name,
221
222
  )
222
- files = _prepare_create_step_files(container_config, data, function_path)
223
+ files = _prepare_create_step_files(sdk, container_config, data, function_path)
223
224
 
224
225
  log_action(
225
226
  sdk,
@@ -414,3 +415,47 @@ def download_pipeline_local_folder(sdk: BaseCraftAiSdk, pipeline_name, folder):
414
415
  f.write(object_content)
415
416
  else:
416
417
  raise ValueError("'folder' must be a string")
418
+
419
+
420
+ @log_func_result("Pipeline logs")
421
+ def get_pipeline_logs(
422
+ sdk: BaseCraftAiSdk,
423
+ pipeline_name,
424
+ from_datetime=None,
425
+ to_datetime=None,
426
+ limit=None,
427
+ ):
428
+ """Get the logs of a pipeline.
429
+
430
+ Args:
431
+ pipeline_name (:obj:`str`): Name of the pipeline.
432
+ from_datetime (:obj:`datetime.time`, optional): Datetime from which the logs
433
+ are collected.
434
+ to_datetime (:obj:`datetime.time`, optional): Datetime until which the logs
435
+ are collected.
436
+ limit (:obj:`int`, optional): Maximum number of logs that are collected.
437
+
438
+ Returns:
439
+ :obj:`list` of :obj:`dict`: List of collected logs represented as dict with
440
+ the following keys:
441
+
442
+ * ``"timestamp"`` (:obj:`str`): Timestamp of the log.
443
+ * ``"message"`` (:obj:`str`): Log message.
444
+ """
445
+ url = f"{sdk.base_environment_api_url}/pipelines/{pipeline_name}/logs"
446
+
447
+ data = {}
448
+ if from_datetime is not None:
449
+ data["from"] = _datetime_to_timestamp_in_ms(from_datetime)
450
+ if to_datetime is not None:
451
+ data["to"] = _datetime_to_timestamp_in_ms(to_datetime)
452
+ if limit is not None:
453
+ data["limit"] = limit
454
+
455
+ log_action(
456
+ sdk,
457
+ "Please wait while logs are being fetched. This may take a while...",
458
+ )
459
+ logs = sdk._post(url, json=data)
460
+
461
+ return logs
@@ -14,6 +14,7 @@ from ..utils import (
14
14
  multipartify,
15
15
  remove_none_values,
16
16
  handle_data_store_response,
17
+ _datetime_to_timestamp_in_ms,
17
18
  )
18
19
  from ..constants import CREATION_REQUESTS_RETRY_INTERVAL
19
20
 
@@ -73,17 +74,30 @@ def _prepare_create_step_data(
73
74
  return data
74
75
 
75
76
 
76
- def _prepare_create_step_files(container_config, data, function_path):
77
- files = {}
78
- if container_config.get("local_folder") is not None:
79
- included = list(data.get("container_config", {}).get("included_folders", ["/"]))
80
- included.append(data.get("container_config", {}).get("requirements_path"))
81
- included.append(function_path)
82
- tar_data = _compress_folder_to_memory(
83
- container_config["local_folder"], include=list(filter(None, included))
84
- )
85
- files["step_file"] = tar_data
86
- return files
77
+ def _prepare_create_step_files(sdk, container_config, data, function_path):
78
+ if "local_folder" not in container_config:
79
+ return {}
80
+
81
+ url = f"{sdk.base_environment_api_url}/project-information"
82
+ project_information = sdk._get(url)
83
+
84
+ included = [
85
+ *(
86
+ data.get("container_config", {}).get(
87
+ "included_folders", project_information.get("included_folders")
88
+ )
89
+ or []
90
+ ),
91
+ data.get("container_config", {}).get(
92
+ "requirements_path", project_information.get("requirements_path")
93
+ ),
94
+ function_path,
95
+ ]
96
+
97
+ tar_data = _compress_folder_to_memory(
98
+ container_config["local_folder"], include=list(filter(None, included))
99
+ )
100
+ return {"step_file": tar_data}
87
101
 
88
102
 
89
103
  def _add_inputs_outputs_in_message(message, inputs, outputs):
@@ -286,7 +300,7 @@ def create_step(
286
300
  outputs,
287
301
  step_name=step_name,
288
302
  )
289
- files = _prepare_create_step_files(container_config, data, function_path)
303
+ files = _prepare_create_step_files(sdk, container_config, data, function_path)
290
304
 
291
305
  log_action(
292
306
  sdk,
@@ -403,15 +417,6 @@ def list_steps(sdk: BaseCraftAiSdk):
403
417
  * ``"step_name"`` (:obj:`str`): Name of the step.
404
418
  * ``"status"`` (:obj:`str`): either ``"creation_pending"`` or ``"ready"``.
405
419
  * ``"created_at"`` (:obj:`str`): The creation date in ISO format.
406
- * ``"updated_at"`` (:obj:`str`): The last update date in ISO format.
407
- * ``"repository_branch"`` (:obj:`str`): The branch of the
408
- repository where the step was built.
409
- * ``"repository_url"`` (:obj:`str`): The url of the repository
410
- where the step was built.
411
- * ``"commit_id"`` (:obj:`str`): The commit id on which the step was
412
- built.
413
- * ``"origin"`` (:obj:`str`): The origin of the step, can be
414
- ``"git_repository"`` or ``"local"``.
415
420
  """
416
421
  url = f"{sdk.base_environment_api_url}/steps"
417
422
 
@@ -474,3 +479,47 @@ def download_step_local_folder(sdk: BaseCraftAiSdk, step_name, folder):
474
479
  f.write(object_content)
475
480
  else:
476
481
  raise ValueError("'folder' must be a string")
482
+
483
+
484
+ @log_func_result("Step logs")
485
+ def get_step_logs(
486
+ sdk: BaseCraftAiSdk,
487
+ step_name,
488
+ from_datetime=None,
489
+ to_datetime=None,
490
+ limit=None,
491
+ ):
492
+ """Get the logs of a step.
493
+
494
+ Args:
495
+ step_name (:obj:`str`): Name of the step.
496
+ from_datetime (:obj:`datetime.time`, optional): Datetime from which the logs
497
+ are collected.
498
+ to_datetime (:obj:`datetime.time`, optional): Datetime until which the logs
499
+ are collected.
500
+ limit (:obj:`int`, optional): Maximum number of logs that are collected.
501
+
502
+ Returns:
503
+ :obj:`list` of :obj:`dict`: List of collected logs represented as dict with
504
+ the following keys:
505
+
506
+ * ``"timestamp"`` (:obj:`str`): Timestamp of the log.
507
+ * ``"message"`` (:obj:`str`): Log message.
508
+ """
509
+ url = f"{sdk.base_environment_api_url}/steps/{step_name}/logs"
510
+
511
+ data = {}
512
+ if from_datetime is not None:
513
+ data["from"] = _datetime_to_timestamp_in_ms(from_datetime)
514
+ if to_datetime is not None:
515
+ data["to"] = _datetime_to_timestamp_in_ms(to_datetime)
516
+ if limit is not None:
517
+ data["limit"] = limit
518
+
519
+ log_action(
520
+ sdk,
521
+ "Please wait while logs are being fetched. This may take a while...",
522
+ )
523
+ logs = sdk._post(url, json=data)
524
+
525
+ return logs
@@ -59,6 +59,7 @@ class CraftAiSdk(BaseCraftAiSdk):
59
59
  list_steps,
60
60
  delete_step,
61
61
  download_step_local_folder,
62
+ get_step_logs,
62
63
  )
63
64
  from .core.pipelines import (
64
65
  create_pipeline,
@@ -66,6 +67,7 @@ class CraftAiSdk(BaseCraftAiSdk):
66
67
  list_pipelines,
67
68
  delete_pipeline,
68
69
  download_pipeline_local_folder,
70
+ get_pipeline_logs,
69
71
  )
70
72
  from .core.pipeline_executions import (
71
73
  run_pipeline,
@@ -128,7 +130,7 @@ class CraftAiSdk(BaseCraftAiSdk):
128
130
  os.environ.get("CRAFT_AI__MULTIPART_PART_SIZE__B", str(38 * 256 * 1024))
129
131
  )
130
132
  _access_token_margin = timedelta(seconds=30)
131
- _version = "0.50.1rc2" # Would be better to share it somewhere
133
+ _version = "0.51.0rc1" # Would be better to share it somewhere
132
134
 
133
135
  def __init__(
134
136
  self,
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "craft-ai-sdk"
3
- version = "0.50.1rc2"
3
+ version = "0.51.0rc1"
4
4
  description = "Craft AI MLOps platform SDK"
5
5
  license = "Apache-2.0"
6
6
  authors = ["Craft AI <contact@craft.ai>"]
@@ -24,7 +24,7 @@ entry_points = \
24
24
 
25
25
  setup_kwargs = {
26
26
  'name': 'craft-ai-sdk',
27
- 'version': '0.50.1rc2',
27
+ 'version': '0.51.0rc1',
28
28
  'description': 'Craft AI MLOps platform SDK',
29
29
  'long_description': '# Craft AI Python SDK\n\nThis Python SDK lets you interact with Craft AI MLOps Platform.\n\n## Installation\nThis project relies on **Python 3.8+**. Once a supported version of Python is installed, you can install `craft-ai-sdk` from PyPI with:\n\n```console\npip install craft-ai-sdk\n```\n\n## Basic usage\nYou can configure the SDK by instantiating the `CraftAiSdk` class in this way:\n\n```python\nfrom craft_ai_sdk import CraftAiSdk\n\nCRAFT_AI_SDK_TOKEN = # your access key obtained from your settings page\nCRAFT_AI_ENVIRONMENT_URL = # url to your environment\n\nsdk = CraftAiSdk(sdk_token=CRAFT_AI_SDK_TOKEN, environment_url=CRAFT_AI_ENVIRONMENT_URL)\n```\n\nIf using the SDK in interactive mode, some additional feedbacks will be printed. You can force disable or enable those logs by either\n* Setting the `verbose_log` SDK parameter\n* Or setting the `SDK_VERBOSE_LOG` env var\n',
30
30
  'author': 'Craft AI',