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,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.artifact.builder import artifact_from_dict, artifact_from_parameters
14
+ from digitalhub.entities.entity_types import EntityTypes
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.artifact.entity._base import Artifact
21
+
22
+
23
+ ENTITY_TYPE = EntityTypes.ARTIFACT.value
24
+
25
+
26
+ def new_artifact(
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
+ ) -> Artifact:
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
+ Artifact
64
+ Object instance.
65
+
66
+ Examples
67
+ --------
68
+ >>> obj = new_artifact(project="my-project",
69
+ >>> name="my-artifact",
70
+ >>> kind="artifact",
71
+ >>> path="s3://my-bucket/my-key")
72
+ """
73
+ check_context(project)
74
+ obj = artifact_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_artifact(
90
+ project: str,
91
+ name: str,
92
+ kind: str,
93
+ source: list[str] | str,
94
+ path: str | None = None,
95
+ **kwargs,
96
+ ) -> Artifact:
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
+ Artifact location on local path.
110
+ path : str
111
+ Destination path of the artifact. If not provided, it's generated.
112
+ **kwargs : dict
113
+ New artifact spec parameters.
114
+
115
+ Returns
116
+ -------
117
+ Artifact
118
+ Object instance.
119
+
120
+ Examples
121
+ --------
122
+ >>> obj = log_artifact(project="my-project",
123
+ >>> name="my-artifact",
124
+ >>> kind="artifact",
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_artifact(project=project, name=name, kind=kind, path=path, **kwargs)
135
+ obj.upload(source)
136
+ return obj
137
+
138
+
139
+ def get_artifact(
140
+ identifier: str,
141
+ project: str | None = None,
142
+ entity_id: str | None = None,
143
+ **kwargs,
144
+ ) -> Artifact:
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
+ Artifact
162
+ Object instance.
163
+
164
+ Examples
165
+ --------
166
+ Using entity key:
167
+ >>> obj = get_artifact("store://my-artifact-key")
168
+
169
+ Using entity name:
170
+ >>> obj = get_artifact("my-artifact-name"
171
+ >>> project="my-project",
172
+ >>> entity_id="my-artifact-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 = artifact_from_dict(obj)
182
+ entity._get_files_info()
183
+ return entity
184
+
185
+
186
+ def get_artifact_versions(
187
+ identifier: str,
188
+ project: str | None = None,
189
+ **kwargs,
190
+ ) -> list[Artifact]:
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[Artifact]
206
+ List of object instances.
207
+
208
+ Examples
209
+ --------
210
+ Using entity key:
211
+ >>> obj = get_artifact_versions("store://my-artifact-key")
212
+
213
+ Using entity name:
214
+ >>> obj = get_artifact_versions("my-artifact-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 = artifact_from_dict(o)
226
+ entity._get_files_info()
227
+ objects.append(entity)
228
+ return objects
229
+
230
+
231
+ def list_artifacts(project: str, **kwargs) -> list[Artifact]:
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[Artifact]
245
+ List of object instances.
246
+
247
+ Examples
248
+ --------
249
+ >>> objs = list_artifacts(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 = artifact_from_dict(o)
259
+ entity._get_files_info()
260
+ objects.append(entity)
261
+ return objects
262
+
263
+
264
+ def import_artifact(file: str) -> Artifact:
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
+ Artifact
276
+ Object instance.
277
+
278
+ Examples
279
+ --------
280
+ >>> obj = import_artifact("my-artifact.yaml")
281
+ """
282
+ dict_obj: dict = read_yaml(file)
283
+ obj = artifact_from_dict(dict_obj)
284
+ try:
285
+ obj.save()
286
+ except EntityAlreadyExistsError:
287
+ pass
288
+ finally:
289
+ return obj
290
+
291
+
292
+ def update_artifact(entity: Artifact) -> Artifact:
293
+ """
294
+ Update object. Note that object spec are immutable.
295
+
296
+ Parameters
297
+ ----------
298
+ entity : Artifact
299
+ Object to update.
300
+
301
+ Returns
302
+ -------
303
+ Artifact
304
+ Entity updated.
305
+
306
+ Examples
307
+ --------
308
+ >>> obj = update_artifact(obj)
309
+ """
310
+ return entity.save(update=True)
311
+
312
+
313
+ def delete_artifact(
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
+ >>> delete_artifact("store://my-artifact-key")
345
+
346
+ Otherwise:
347
+ >>> delete_artifact("my-artifact-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
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from digitalhub.entities._base.entity.material import MaterialEntity
6
+ from digitalhub.entities.entity_types import EntityTypes
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from digitalhub.entities._base.metadata import Metadata
10
+ from digitalhub.entities.artifact.spec import ArtifactSpec
11
+ from digitalhub.entities.artifact.status import ArtifactStatus
12
+
13
+
14
+ class Artifact(MaterialEntity):
15
+ """
16
+ A class representing a artifact.
17
+
18
+ Artifacts are (binary) objects stored in one of the artifact
19
+ stores of the platform, and available to every process, module
20
+ and component as files.
21
+ """
22
+
23
+ ENTITY_TYPE = EntityTypes.ARTIFACT.value
24
+
25
+ def __init__(
26
+ self,
27
+ project: str,
28
+ name: str,
29
+ uuid: str,
30
+ kind: str,
31
+ metadata: Metadata,
32
+ spec: ArtifactSpec,
33
+ status: ArtifactStatus,
34
+ user: str | None = None,
35
+ ) -> None:
36
+ super().__init__(project, name, uuid, kind, metadata, spec, status, user)
37
+
38
+ self.spec: ArtifactSpec
39
+ self.status: ArtifactStatus
@@ -0,0 +1,9 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities.artifact.entity._base import Artifact
4
+
5
+
6
+ class ArtifactArtifact(Artifact):
7
+ """
8
+ Artifact class.
9
+ """
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.spec.material import MaterialParams, MaterialSpec
4
+
5
+
6
+ class ArtifactSpec(MaterialSpec):
7
+ """
8
+ Artifact specification.
9
+ """
10
+
11
+
12
+ class ArtifactParams(MaterialParams):
13
+ """
14
+ Artifact base parameters.
15
+ """
16
+
17
+
18
+ class ArtifactSpecArtifact(ArtifactSpec):
19
+ """
20
+ Artifact specification.
21
+ """
22
+
23
+ def __init__(
24
+ self,
25
+ path: str,
26
+ src_path: str | None = None,
27
+ **kwargs,
28
+ ) -> None:
29
+ super().__init__(path, **kwargs)
30
+ self.src_path = src_path
31
+
32
+
33
+ class ArtifactParamsArtifact(ArtifactParams):
34
+ """
35
+ Artifact parameters.
36
+ """
37
+
38
+ src_path: str = None
39
+ """Source path of the artifact."""
@@ -0,0 +1,15 @@
1
+ from __future__ import annotations
2
+
3
+ from digitalhub.entities._base.status.material import MaterialStatus
4
+
5
+
6
+ class ArtifactStatus(MaterialStatus):
7
+ """
8
+ Status class for artifact entities.
9
+ """
10
+
11
+
12
+ class ArtifactStatusArtifact(ArtifactStatus):
13
+ """
14
+ Status class for artifact entities.
15
+ """
File without changes
@@ -0,0 +1,144 @@
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.dataitem.entity._base import Dataitem
14
+
15
+ # Manage class mapper
16
+ cls_mapper = {}
17
+ try:
18
+ from digitalhub.entities.dataitem.entity.dataitem import DataitemDataitem
19
+
20
+ cls_mapper["dataitem"] = DataitemDataitem
21
+ except ImportError:
22
+ ...
23
+ try:
24
+ from digitalhub.entities.dataitem.entity.table import DataitemTable
25
+
26
+ cls_mapper["table"] = DataitemTable
27
+ except ImportError:
28
+ ...
29
+ try:
30
+ from digitalhub.entities.dataitem.entity.iceberg import DataitemIceberg
31
+
32
+ cls_mapper["iceberg"] = DataitemIceberg
33
+ except ImportError:
34
+ pass
35
+
36
+
37
+ def _choose_dataitem_type(kind: str) -> type[Dataitem]:
38
+ """
39
+ Choose class based on kind.
40
+
41
+ Parameters
42
+ ----------
43
+ kind : str
44
+ Kind the object.
45
+
46
+ Returns
47
+ -------
48
+ type[Dataitem]
49
+ Class of the dataitem.
50
+ """
51
+ try:
52
+ return cls_mapper[kind]
53
+ except KeyError:
54
+ raise EntityError(f"Unknown dataitem kind: {kind}")
55
+
56
+
57
+ def dataitem_from_parameters(
58
+ project: str,
59
+ name: str,
60
+ kind: str,
61
+ uuid: str | None = None,
62
+ description: str | None = None,
63
+ labels: list[str] | None = None,
64
+ embedded: bool = True,
65
+ path: str | None = None,
66
+ **kwargs,
67
+ ) -> Dataitem:
68
+ """
69
+ Create a new object.
70
+
71
+ Parameters
72
+ ----------
73
+ project : str
74
+ Project name.
75
+ name : str
76
+ Object name.
77
+ kind : str
78
+ Kind the object.
79
+ uuid : str
80
+ ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
81
+ description : str
82
+ Description of the object (human readable).
83
+ labels : list[str]
84
+ List of labels.
85
+ embedded : bool
86
+ Flag to determine if object spec must be embedded in project spec.
87
+ path : str
88
+ Object path on local file system or remote storage. It is also the destination path of upload() method.
89
+ **kwargs : dict
90
+ Spec keyword arguments.
91
+
92
+ Returns
93
+ -------
94
+ Dataitem
95
+ Object instance.
96
+ """
97
+ if path is None:
98
+ raise EntityError("Dataitem path must be provided")
99
+ name = build_name(name)
100
+ uuid = build_uuid(uuid)
101
+ metadata = build_metadata(
102
+ kind,
103
+ project=project,
104
+ name=name,
105
+ version=uuid,
106
+ description=description,
107
+ labels=labels,
108
+ embedded=embedded,
109
+ )
110
+ spec = build_spec(
111
+ kind,
112
+ path=path,
113
+ **kwargs,
114
+ )
115
+ status = build_status(kind)
116
+ cls = _choose_dataitem_type(kind)
117
+ return cls(
118
+ project=project,
119
+ name=name,
120
+ uuid=uuid,
121
+ kind=kind,
122
+ metadata=metadata,
123
+ spec=spec,
124
+ status=status,
125
+ )
126
+
127
+
128
+ def dataitem_from_dict(obj: dict) -> Dataitem:
129
+ """
130
+ Create a new object from dictionary.
131
+
132
+ Parameters
133
+ ----------
134
+ obj : dict
135
+ Dictionary to create object from.
136
+
137
+ Returns
138
+ -------
139
+ Dataitem
140
+ Object instance.
141
+ """
142
+ kind = obj.get("kind")
143
+ cls = _choose_dataitem_type(kind)
144
+ return cls.from_dict(obj)