digitalhub 0.8.0b0__py3-none-any.whl → 0.8.0b2__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.

Potentially problematic release.


This version of digitalhub might be problematic. Click here for more details.

Files changed (159) hide show
  1. digitalhub/__init__.py +62 -94
  2. digitalhub/client/__init__.py +0 -0
  3. digitalhub/client/builder.py +105 -0
  4. digitalhub/client/objects/__init__.py +0 -0
  5. digitalhub/client/objects/base.py +56 -0
  6. digitalhub/client/objects/dhcore.py +681 -0
  7. digitalhub/client/objects/local.py +533 -0
  8. digitalhub/context/__init__.py +0 -0
  9. digitalhub/context/builder.py +178 -0
  10. digitalhub/context/context.py +136 -0
  11. digitalhub/datastores/__init__.py +0 -0
  12. digitalhub/datastores/builder.py +134 -0
  13. digitalhub/datastores/objects/__init__.py +0 -0
  14. digitalhub/datastores/objects/base.py +85 -0
  15. digitalhub/datastores/objects/local.py +42 -0
  16. digitalhub/datastores/objects/remote.py +23 -0
  17. digitalhub/datastores/objects/s3.py +38 -0
  18. digitalhub/datastores/objects/sql.py +60 -0
  19. digitalhub/entities/__init__.py +0 -0
  20. digitalhub/entities/_base/__init__.py +0 -0
  21. digitalhub/entities/_base/api.py +346 -0
  22. digitalhub/entities/_base/base.py +82 -0
  23. digitalhub/entities/_base/crud.py +610 -0
  24. digitalhub/entities/_base/entity/__init__.py +0 -0
  25. digitalhub/entities/_base/entity/base.py +132 -0
  26. digitalhub/entities/_base/entity/context.py +118 -0
  27. digitalhub/entities/_base/entity/executable.py +380 -0
  28. digitalhub/entities/_base/entity/material.py +214 -0
  29. digitalhub/entities/_base/entity/unversioned.py +87 -0
  30. digitalhub/entities/_base/entity/versioned.py +94 -0
  31. digitalhub/entities/_base/metadata.py +59 -0
  32. digitalhub/entities/_base/spec/__init__.py +0 -0
  33. digitalhub/entities/_base/spec/base.py +58 -0
  34. digitalhub/entities/_base/spec/material.py +22 -0
  35. digitalhub/entities/_base/state.py +31 -0
  36. digitalhub/entities/_base/status/__init__.py +0 -0
  37. digitalhub/entities/_base/status/base.py +32 -0
  38. digitalhub/entities/_base/status/material.py +49 -0
  39. digitalhub/entities/_builders/__init__.py +0 -0
  40. digitalhub/entities/_builders/metadata.py +60 -0
  41. digitalhub/entities/_builders/name.py +31 -0
  42. digitalhub/entities/_builders/spec.py +43 -0
  43. digitalhub/entities/_builders/status.py +62 -0
  44. digitalhub/entities/_builders/uuid.py +33 -0
  45. digitalhub/entities/artifact/__init__.py +0 -0
  46. digitalhub/entities/artifact/builder.py +133 -0
  47. digitalhub/entities/artifact/crud.py +358 -0
  48. digitalhub/entities/artifact/entity/__init__.py +0 -0
  49. digitalhub/entities/artifact/entity/_base.py +39 -0
  50. digitalhub/entities/artifact/entity/artifact.py +9 -0
  51. digitalhub/entities/artifact/spec.py +39 -0
  52. digitalhub/entities/artifact/status.py +15 -0
  53. digitalhub/entities/dataitem/__init__.py +0 -0
  54. digitalhub/entities/dataitem/builder.py +144 -0
  55. digitalhub/entities/dataitem/crud.py +395 -0
  56. digitalhub/entities/dataitem/entity/__init__.py +0 -0
  57. digitalhub/entities/dataitem/entity/_base.py +75 -0
  58. digitalhub/entities/dataitem/entity/dataitem.py +9 -0
  59. digitalhub/entities/dataitem/entity/iceberg.py +7 -0
  60. digitalhub/entities/dataitem/entity/table.py +125 -0
  61. digitalhub/entities/dataitem/models.py +62 -0
  62. digitalhub/entities/dataitem/spec.py +61 -0
  63. digitalhub/entities/dataitem/status.py +38 -0
  64. digitalhub/entities/entity_types.py +19 -0
  65. digitalhub/entities/function/__init__.py +0 -0
  66. digitalhub/entities/function/builder.py +86 -0
  67. digitalhub/entities/function/crud.py +305 -0
  68. digitalhub/entities/function/entity.py +101 -0
  69. digitalhub/entities/function/models.py +118 -0
  70. digitalhub/entities/function/spec.py +81 -0
  71. digitalhub/entities/function/status.py +9 -0
  72. digitalhub/entities/model/__init__.py +0 -0
  73. digitalhub/entities/model/builder.py +152 -0
  74. digitalhub/entities/model/crud.py +358 -0
  75. digitalhub/entities/model/entity/__init__.py +0 -0
  76. digitalhub/entities/model/entity/_base.py +34 -0
  77. digitalhub/entities/model/entity/huggingface.py +9 -0
  78. digitalhub/entities/model/entity/mlflow.py +90 -0
  79. digitalhub/entities/model/entity/model.py +9 -0
  80. digitalhub/entities/model/entity/sklearn.py +9 -0
  81. digitalhub/entities/model/models.py +26 -0
  82. digitalhub/entities/model/spec.py +146 -0
  83. digitalhub/entities/model/status.py +33 -0
  84. digitalhub/entities/project/__init__.py +0 -0
  85. digitalhub/entities/project/builder.py +82 -0
  86. digitalhub/entities/project/crud.py +350 -0
  87. digitalhub/entities/project/entity.py +2060 -0
  88. digitalhub/entities/project/spec.py +50 -0
  89. digitalhub/entities/project/status.py +9 -0
  90. digitalhub/entities/registries.py +48 -0
  91. digitalhub/entities/run/__init__.py +0 -0
  92. digitalhub/entities/run/builder.py +77 -0
  93. digitalhub/entities/run/crud.py +232 -0
  94. digitalhub/entities/run/entity.py +461 -0
  95. digitalhub/entities/run/spec.py +153 -0
  96. digitalhub/entities/run/status.py +114 -0
  97. digitalhub/entities/secret/__init__.py +0 -0
  98. digitalhub/entities/secret/builder.py +93 -0
  99. digitalhub/entities/secret/crud.py +294 -0
  100. digitalhub/entities/secret/entity.py +73 -0
  101. digitalhub/entities/secret/spec.py +35 -0
  102. digitalhub/entities/secret/status.py +9 -0
  103. digitalhub/entities/task/__init__.py +0 -0
  104. digitalhub/entities/task/builder.py +74 -0
  105. digitalhub/entities/task/crud.py +241 -0
  106. digitalhub/entities/task/entity.py +135 -0
  107. digitalhub/entities/task/models.py +199 -0
  108. digitalhub/entities/task/spec.py +51 -0
  109. digitalhub/entities/task/status.py +9 -0
  110. digitalhub/entities/utils.py +184 -0
  111. digitalhub/entities/workflow/__init__.py +0 -0
  112. digitalhub/entities/workflow/builder.py +91 -0
  113. digitalhub/entities/workflow/crud.py +304 -0
  114. digitalhub/entities/workflow/entity.py +77 -0
  115. digitalhub/entities/workflow/spec.py +15 -0
  116. digitalhub/entities/workflow/status.py +9 -0
  117. digitalhub/readers/__init__.py +0 -0
  118. digitalhub/readers/builder.py +54 -0
  119. digitalhub/readers/objects/__init__.py +0 -0
  120. digitalhub/readers/objects/base.py +70 -0
  121. digitalhub/readers/objects/pandas.py +207 -0
  122. digitalhub/readers/registry.py +15 -0
  123. digitalhub/registry/__init__.py +0 -0
  124. digitalhub/registry/models.py +87 -0
  125. digitalhub/registry/registry.py +74 -0
  126. digitalhub/registry/utils.py +150 -0
  127. digitalhub/runtimes/__init__.py +0 -0
  128. digitalhub/runtimes/base.py +164 -0
  129. digitalhub/runtimes/builder.py +53 -0
  130. digitalhub/runtimes/kind_registry.py +170 -0
  131. digitalhub/stores/__init__.py +0 -0
  132. digitalhub/stores/builder.py +257 -0
  133. digitalhub/stores/objects/__init__.py +0 -0
  134. digitalhub/stores/objects/base.py +189 -0
  135. digitalhub/stores/objects/local.py +230 -0
  136. digitalhub/stores/objects/remote.py +143 -0
  137. digitalhub/stores/objects/s3.py +563 -0
  138. digitalhub/stores/objects/sql.py +328 -0
  139. digitalhub/utils/__init__.py +0 -0
  140. digitalhub/utils/data_utils.py +127 -0
  141. digitalhub/utils/env_utils.py +123 -0
  142. digitalhub/utils/exceptions.py +55 -0
  143. digitalhub/utils/file_utils.py +204 -0
  144. digitalhub/utils/generic_utils.py +207 -0
  145. digitalhub/utils/git_utils.py +148 -0
  146. digitalhub/utils/io_utils.py +79 -0
  147. digitalhub/utils/logger.py +17 -0
  148. digitalhub/utils/uri_utils.py +56 -0
  149. {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/METADATA +27 -12
  150. digitalhub-0.8.0b2.dist-info/RECORD +161 -0
  151. test/test_crud_artifacts.py +1 -1
  152. test/test_crud_dataitems.py +1 -1
  153. test/test_crud_functions.py +1 -1
  154. test/test_crud_runs.py +1 -1
  155. test/test_crud_tasks.py +1 -1
  156. digitalhub-0.8.0b0.dist-info/RECORD +0 -14
  157. {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/LICENSE.txt +0 -0
  158. {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/WHEEL +0 -0
  159. {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,118 @@
1
+ from __future__ import annotations
2
+
3
+ from abc import abstractmethod
4
+ from pathlib import Path
5
+
6
+ from pydantic import BaseModel
7
+
8
+ from digitalhub.utils.exceptions import EntityError
9
+ from digitalhub.utils.generic_utils import decode_string
10
+ from digitalhub.utils.uri_utils import map_uri_scheme
11
+
12
+
13
+ class SourceCodeStruct:
14
+ """
15
+ Source code struct.
16
+ """
17
+
18
+ def __init__(
19
+ self,
20
+ source: str | None = None,
21
+ code: str | None = None,
22
+ base64: str | None = None,
23
+ handler: str | None = None,
24
+ lang: str | None = None,
25
+ ) -> None:
26
+ self.source = source
27
+ self.code = code
28
+ self.base64 = base64
29
+ self.handler = handler
30
+ self.lang = lang
31
+
32
+ @staticmethod
33
+ @abstractmethod
34
+ def source_check(source: dict) -> dict:
35
+ """
36
+ Check source.
37
+
38
+ Parameters
39
+ ----------
40
+ source : dict
41
+ Source.
42
+
43
+ Returns
44
+ -------
45
+ dict
46
+ Checked source.
47
+ """
48
+
49
+ def show_source_code(self) -> str:
50
+ """
51
+ Show source code.
52
+
53
+ Returns
54
+ -------
55
+ str
56
+ Source code.
57
+ """
58
+ if self.code is not None:
59
+ return self.code
60
+ if self.base64 is not None:
61
+ try:
62
+ return decode_string(self.base64)
63
+ except Exception:
64
+ raise EntityError("Something got wrong during source code decoding.")
65
+ if (self.source is not None) and (map_uri_scheme(self.source) == "local"):
66
+ try:
67
+ return Path(self.source).read_text()
68
+ except Exception:
69
+ raise EntityError("Cannot access source code.")
70
+ return ""
71
+
72
+ def to_dict(self) -> dict:
73
+ """
74
+ Convert to dictionary.
75
+
76
+ Returns
77
+ -------
78
+ dict
79
+ Dictionary representation of the object.
80
+ """
81
+ dict_ = {}
82
+ if self.source is not None:
83
+ dict_["source"] = self.source
84
+ if self.base64 is not None:
85
+ dict_["base64"] = self.base64
86
+ if self.handler is not None:
87
+ dict_["handler"] = self.handler
88
+ if self.lang is not None:
89
+ dict_["lang"] = self.lang
90
+
91
+ return dict_
92
+
93
+ def __repr__(self) -> str:
94
+ return str(self.to_dict())
95
+
96
+
97
+ class SourceCodeParams(BaseModel):
98
+ """
99
+ Source code params.
100
+ """
101
+
102
+ source: dict = None
103
+ "Source code details as dictionary"
104
+
105
+ code_src: str = None
106
+ "Pointer to source code"
107
+
108
+ handler: str = None
109
+ "Function entrypoint"
110
+
111
+ code: str = None
112
+ "Source code (plain text)"
113
+
114
+ base64: str = None
115
+ "Source code (base64 encoded)"
116
+
117
+ lang: str = None
118
+ "Source code language (hint)"
@@ -0,0 +1,81 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.spec.base import Spec, SpecParams
4
+
5
+
6
+ class FunctionSpec(Spec):
7
+ """
8
+ Specification for a Function.
9
+ """
10
+
11
+
12
+ class FunctionParams(SpecParams):
13
+ """
14
+ Function parameters model.
15
+ """
16
+
17
+
18
+ class SourceCodeStruct:
19
+ """
20
+ Source code struct.
21
+ """
22
+
23
+ def __init__(
24
+ self,
25
+ source: str | None = None,
26
+ handler: str | None = None,
27
+ code: str | None = None,
28
+ base64: str | None = None,
29
+ init_function: str | None = None,
30
+ lang: str | None = None,
31
+ ) -> None:
32
+ """
33
+ Constructor.
34
+
35
+ Parameters
36
+ ----------
37
+ source : str
38
+ Source reference.
39
+ handler : str
40
+ Function entrypoint.
41
+ code : str
42
+ Source code (plain).
43
+ base64 : str
44
+ Source code (base64 encoded).
45
+ init_function : str
46
+ Init function for remote execution.
47
+ lang : str
48
+ Source code language (hint).
49
+ """
50
+ self.source = source
51
+ self.handler = handler
52
+ self.code = code
53
+ self.base64 = base64
54
+ self.init_function = init_function
55
+ self.lang = lang
56
+
57
+ def to_dict(self) -> dict:
58
+ """
59
+ Convert to dictionary.
60
+
61
+ Returns
62
+ -------
63
+ dict
64
+ Dictionary representation of the object.
65
+ """
66
+ dict_ = {}
67
+ if self.source is not None:
68
+ dict_["source"] = self.source
69
+ if self.handler is not None:
70
+ dict_["handler"] = self.handler
71
+ if self.base64 is not None:
72
+ dict_["base64"] = self.base64
73
+ if self.init_function is not None:
74
+ dict_["init_function"] = self.init_function
75
+ if self.lang is not None:
76
+ dict_["lang"] = self.lang
77
+
78
+ return dict_
79
+
80
+ def __repr__(self) -> str:
81
+ return str(self.to_dict())
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.status.base import Status
4
+
5
+
6
+ class FunctionStatus(Status):
7
+ """
8
+ Status class for function entities.
9
+ """
File without changes
@@ -0,0 +1,152 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._builders.metadata import build_metadata
6
+ from digitalhub.entities._builders.name import build_name
7
+ from digitalhub.entities._builders.spec import build_spec
8
+ from digitalhub.entities._builders.status import build_status
9
+ from digitalhub.entities._builders.uuid import build_uuid
10
+ from digitalhub.utils.exceptions import EntityError
11
+
12
+ if typing.TYPE_CHECKING:
13
+ from digitalhub.entities.model.entity._base import Model
14
+
15
+ # Manage class mapper
16
+ cls_mapper = {}
17
+
18
+ try:
19
+ from digitalhub.entities.model.entity.model import ModelModel
20
+
21
+ cls_mapper["model"] = ModelModel
22
+ except ImportError:
23
+ ...
24
+
25
+ try:
26
+ from digitalhub.entities.model.entity.mlflow import ModelMlflow
27
+
28
+ cls_mapper["mlflow"] = ModelMlflow
29
+ except ImportError:
30
+ ...
31
+ try:
32
+ from digitalhub.entities.model.entity.sklearn import ModelSklearn
33
+
34
+ cls_mapper["sklearn"] = ModelSklearn
35
+ except ImportError:
36
+ ...
37
+ try:
38
+ from digitalhub.entities.model.entity.huggingface import ModelHuggingface
39
+
40
+ cls_mapper["huggingface"] = ModelHuggingface
41
+ except ImportError:
42
+ pass
43
+
44
+
45
+ def _choose_model_type(kind: str) -> type[Model]:
46
+ """
47
+ Choose class based on kind.
48
+
49
+ Parameters
50
+ ----------
51
+ kind : str
52
+ Kind the object.
53
+
54
+ Returns
55
+ -------
56
+ type[Model]
57
+ Class of the model.
58
+ """
59
+ try:
60
+ return cls_mapper[kind]
61
+ except KeyError:
62
+ raise EntityError(f"Unknown model kind: {kind}")
63
+
64
+
65
+ def model_from_parameters(
66
+ project: str,
67
+ name: str,
68
+ kind: str,
69
+ uuid: str | None = None,
70
+ description: str | None = None,
71
+ labels: list[str] | None = None,
72
+ embedded: bool = True,
73
+ path: str | None = None,
74
+ **kwargs,
75
+ ) -> Model:
76
+ """
77
+ Create a new object.
78
+
79
+ Parameters
80
+ ----------
81
+ project : str
82
+ Project name.
83
+ name : str
84
+ Object name.
85
+ kind : str
86
+ Kind the object.
87
+ uuid : str
88
+ ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
89
+ labels : list[str]
90
+ List of labels.
91
+ description : str
92
+ Description of the object (human readable).
93
+ embedded : bool
94
+ Flag to determine if object spec must be embedded in project spec.
95
+ path : str
96
+ Object path on local file system or remote storage. It is also the destination path of upload() method.
97
+ **kwargs : dict
98
+ Spec keyword arguments.
99
+
100
+ Returns
101
+ -------
102
+ Model
103
+ Object instance.
104
+ """
105
+ if path is None:
106
+ raise EntityError("Path must be provided.")
107
+ name = build_name(name)
108
+ uuid = build_uuid(uuid)
109
+ metadata = build_metadata(
110
+ kind,
111
+ project=project,
112
+ name=name,
113
+ version=uuid,
114
+ description=description,
115
+ labels=labels,
116
+ embedded=embedded,
117
+ )
118
+ spec = build_spec(
119
+ kind,
120
+ path=path,
121
+ **kwargs,
122
+ )
123
+ status = build_status(kind)
124
+ cls = _choose_model_type(kind)
125
+ return cls(
126
+ project=project,
127
+ name=name,
128
+ uuid=uuid,
129
+ kind=kind,
130
+ metadata=metadata,
131
+ spec=spec,
132
+ status=status,
133
+ )
134
+
135
+
136
+ def model_from_dict(obj: dict) -> Model:
137
+ """
138
+ Create a new object from dictionary.
139
+
140
+ Parameters
141
+ ----------
142
+ obj : dict
143
+ Dictionary to create object from.
144
+
145
+ Returns
146
+ -------
147
+ Model
148
+ Object instance.
149
+ """
150
+ kind = obj.get("kind")
151
+ cls = _choose_model_type(kind)
152
+ return cls.from_dict(obj)
@@ -0,0 +1,358 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.context.builder import check_context
6
+ from digitalhub.entities._base.crud import (
7
+ delete_entity_api_ctx,
8
+ list_entity_api_ctx,
9
+ read_entity_api_ctx,
10
+ read_entity_api_ctx_versions,
11
+ )
12
+ from digitalhub.entities._builders.uuid import build_uuid
13
+ from digitalhub.entities.entity_types import EntityTypes
14
+ from digitalhub.entities.model.builder import model_from_dict, model_from_parameters
15
+ from digitalhub.entities.utils import build_log_path_from_source, eval_local_source
16
+ from digitalhub.utils.exceptions import EntityAlreadyExistsError
17
+ from digitalhub.utils.io_utils import read_yaml
18
+
19
+ if typing.TYPE_CHECKING:
20
+ from digitalhub.entities.model.entity._base import Model
21
+
22
+
23
+ ENTITY_TYPE = EntityTypes.MODEL.value
24
+
25
+
26
+ def new_model(
27
+ project: str,
28
+ name: str,
29
+ kind: str,
30
+ uuid: str | None = None,
31
+ description: str | None = None,
32
+ labels: list[str] | None = None,
33
+ embedded: bool = True,
34
+ path: str | None = None,
35
+ **kwargs,
36
+ ) -> Model:
37
+ """
38
+ Create a new object.
39
+
40
+ Parameters
41
+ ----------
42
+ project : str
43
+ Project name.
44
+ name : str
45
+ Object name.
46
+ kind : str
47
+ Kind the object.
48
+ uuid : str
49
+ ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
50
+ description : str
51
+ Description of the object (human readable).
52
+ labels : list[str]
53
+ List of labels.
54
+ embedded : bool
55
+ Flag to determine if object spec must be embedded in project spec.
56
+ path : str
57
+ Object path on local file system or remote storage. It is also the destination path of upload() method.
58
+ **kwargs : dict
59
+ Spec keyword arguments.
60
+
61
+ Returns
62
+ -------
63
+ Model
64
+ Object instance.
65
+
66
+ Examples
67
+ --------
68
+ >>> obj = new_model(project="my-project",
69
+ >>> name="my-model",
70
+ >>> kind="model",
71
+ >>> path="s3://my-bucket/my-key")
72
+ """
73
+ check_context(project)
74
+ obj = model_from_parameters(
75
+ project=project,
76
+ name=name,
77
+ kind=kind,
78
+ uuid=uuid,
79
+ description=description,
80
+ labels=labels,
81
+ embedded=embedded,
82
+ path=path,
83
+ **kwargs,
84
+ )
85
+ obj.save()
86
+ return obj
87
+
88
+
89
+ def log_model(
90
+ project: str,
91
+ name: str,
92
+ kind: str,
93
+ source: list[str] | str,
94
+ path: str | None = None,
95
+ **kwargs,
96
+ ) -> Model:
97
+ """
98
+ Create and upload an object.
99
+
100
+ Parameters
101
+ ----------
102
+ project : str
103
+ Project name.
104
+ name : str
105
+ Object name.
106
+ kind : str
107
+ Kind the object.
108
+ source : str
109
+ Model location on local path.
110
+ path : str
111
+ Destination path of the model. If not provided, it's generated.
112
+ **kwargs : dict
113
+ New model spec parameters.
114
+
115
+ Returns
116
+ -------
117
+ Model
118
+ Object instance.
119
+
120
+ Examples
121
+ --------
122
+ >>> obj = log_model(project="my-project",
123
+ >>> name="my-model",
124
+ >>> kind="model",
125
+ >>> source="./local-path")
126
+ """
127
+ eval_local_source(source)
128
+
129
+ if path is None:
130
+ uuid = build_uuid()
131
+ kwargs["uuid"] = uuid
132
+ path = build_log_path_from_source(project, ENTITY_TYPE, name, uuid, source)
133
+
134
+ obj = new_model(project=project, name=name, kind=kind, path=path, **kwargs)
135
+ obj.upload(source)
136
+ return obj
137
+
138
+
139
+ def get_model(
140
+ identifier: str,
141
+ project: str | None = None,
142
+ entity_id: str | None = None,
143
+ **kwargs,
144
+ ) -> Model:
145
+ """
146
+ Get object from backend.
147
+
148
+ Parameters
149
+ ----------
150
+ identifier : str
151
+ Entity key (store://...) or entity name.
152
+ project : str
153
+ Project name.
154
+ entity_id : str
155
+ Entity ID.
156
+ **kwargs : dict
157
+ Parameters to pass to the API call.
158
+
159
+ Returns
160
+ -------
161
+ Model
162
+ Object instance.
163
+
164
+ Examples
165
+ --------
166
+ Using entity key:
167
+ >>> obj = get_model("store://my-model-key")
168
+
169
+ Using entity name:
170
+ >>> obj = get_model("my-model-name"
171
+ >>> project="my-project",
172
+ >>> entity_id="my-model-id")
173
+ """
174
+ obj = read_entity_api_ctx(
175
+ identifier,
176
+ ENTITY_TYPE,
177
+ project=project,
178
+ entity_id=entity_id,
179
+ **kwargs,
180
+ )
181
+ entity = model_from_dict(obj)
182
+ entity._get_files_info()
183
+ return entity
184
+
185
+
186
+ def get_model_versions(
187
+ identifier: str,
188
+ project: str | None = None,
189
+ **kwargs,
190
+ ) -> list[Model]:
191
+ """
192
+ Get object versions from backend.
193
+
194
+ Parameters
195
+ ----------
196
+ identifier : str
197
+ Entity key (store://...) or entity name.
198
+ project : str
199
+ Project name.
200
+ **kwargs : dict
201
+ Parameters to pass to the API call.
202
+
203
+ Returns
204
+ -------
205
+ list[Model]
206
+ List of object instances.
207
+
208
+ Examples
209
+ --------
210
+ Using entity key:
211
+ >>> objs = get_model_versions("store://my-model-key")
212
+
213
+ Using entity name:
214
+ >>> objs = get_model_versions("my-model-name",
215
+ >>> project="my-project")
216
+ """
217
+ objs = read_entity_api_ctx_versions(
218
+ identifier,
219
+ entity_type=ENTITY_TYPE,
220
+ project=project,
221
+ **kwargs,
222
+ )
223
+ objects = []
224
+ for o in objs:
225
+ entity = model_from_dict(o)
226
+ entity._get_files_info()
227
+ objects.append(entity)
228
+ return objects
229
+
230
+
231
+ def list_models(project: str, **kwargs) -> list[Model]:
232
+ """
233
+ List all latest version objects from backend.
234
+
235
+ Parameters
236
+ ----------
237
+ project : str
238
+ Project name.
239
+ **kwargs : dict
240
+ Parameters to pass to the API call.
241
+
242
+ Returns
243
+ -------
244
+ list[Model]
245
+ List of object instances.
246
+
247
+ Examples
248
+ --------
249
+ >>> objs = list_models(project="my-project")
250
+ """
251
+ objs = list_entity_api_ctx(
252
+ project=project,
253
+ entity_type=ENTITY_TYPE,
254
+ **kwargs,
255
+ )
256
+ objects = []
257
+ for o in objs:
258
+ entity = model_from_dict(o)
259
+ entity._get_files_info()
260
+ objects.append(entity)
261
+ return objects
262
+
263
+
264
+ def import_model(file: str) -> Model:
265
+ """
266
+ Import object from a YAML file.
267
+
268
+ Parameters
269
+ ----------
270
+ file : str
271
+ Path to YAML file.
272
+
273
+ Returns
274
+ -------
275
+ Model
276
+ Object instance.
277
+
278
+ Examples
279
+ --------
280
+ >>> obj = import_model("my-model.yaml")
281
+ """
282
+ dict_obj: dict = read_yaml(file)
283
+ obj = model_from_dict(dict_obj)
284
+ try:
285
+ obj.save()
286
+ except EntityAlreadyExistsError:
287
+ pass
288
+ finally:
289
+ return obj
290
+
291
+
292
+ def update_model(entity: Model) -> Model:
293
+ """
294
+ Update object. Note that object spec are immutable.
295
+
296
+ Parameters
297
+ ----------
298
+ entity : Model
299
+ Object to update.
300
+
301
+ Returns
302
+ -------
303
+ Model
304
+ Entity updated.
305
+
306
+ Examples
307
+ --------
308
+ >>> obj = get_model("store://my-model-key")
309
+ """
310
+ return entity.save(update=True)
311
+
312
+
313
+ def delete_model(
314
+ identifier: str,
315
+ project: str | None = None,
316
+ entity_id: str | None = None,
317
+ delete_all_versions: bool = False,
318
+ **kwargs,
319
+ ) -> dict:
320
+ """
321
+ Delete object from backend.
322
+
323
+ Parameters
324
+ ----------
325
+ identifier : str
326
+ Entity key (store://...) or entity name.
327
+ project : str
328
+ Project name.
329
+ entity_id : str
330
+ Entity ID.
331
+ delete_all_versions : bool
332
+ Delete all versions of the named entity. If True, use entity name instead of entity key as identifier.
333
+ **kwargs : dict
334
+ Parameters to pass to the API call.
335
+
336
+ Returns
337
+ -------
338
+ dict
339
+ Response from backend.
340
+
341
+ Examples
342
+ --------
343
+ If delete_all_versions is False:
344
+ >>> obj = delete_model("store://my-model-key")
345
+
346
+ Otherwise:
347
+ >>> obj = delete_model("my-model-name",
348
+ >>> project="my-project",
349
+ >>> delete_all_versions=True)
350
+ """
351
+ return delete_entity_api_ctx(
352
+ identifier=identifier,
353
+ entity_type=ENTITY_TYPE,
354
+ project=project,
355
+ entity_id=entity_id,
356
+ delete_all_versions=delete_all_versions,
357
+ **kwargs,
358
+ )
File without changes