Skip to content

Entity and methods

Project

Bases: Entity

A class representing a project.

Source code in digitalhub_core/entities/projects/entity.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
class Project(Entity):
    """
    A class representing a project.
    """

    ENTITY_TYPE = EntityTypes.PROJECTS.value

    def __init__(
        self,
        name: str,
        kind: str,
        metadata: Metadata,
        spec: ProjectSpec,
        status: ProjectStatus,
        user: str | None = None,
        local: bool = False,
    ) -> None:
        """
        Constructor.

        Parameters
        ----------
        name : str
            Name of the object.
        kind : str
            Kind the object.
        metadata : Metadata
            Metadata of the object.
        spec : ProjectSpec
            Specification of the object.
        status : ProjectStatus
            Status of the object.
        user : str
            Owner of the object.
        local: bool
            If True, export locally.
        """
        super().__init__()
        self.id = name
        self.name = name
        self.kind = kind
        self.key = f"store://{name}"
        self.metadata = metadata
        self.spec = spec
        self.status = status
        self.user = user

        # Add attributes to be used in the to_dict method
        self._obj_attr.extend(["id", "name", "key"])

        # Set client
        self._client = get_client(local)

        # Set context
        set_context(self)

    #############################
    #  Save / Refresh / Export
    #############################

    def save(self, update: bool = False) -> Project:
        """
        Save entity into backend.

        Parameters
        ----------
        update : bool
            If True, the object will be updated.

        Returns
        -------
        Project
            Entity saved.
        """
        obj = self._refresh_to_dict()

        if not update:
            new_obj = create_entity_api_base(self._client, self.ENTITY_TYPE, obj)
            new_obj["local"] = self._client.is_local()
            self._update_attributes(new_obj)
            return self

        self.metadata.updated = obj["metadata"]["updated"] = get_timestamp()
        new_obj = update_entity_api_base(self._client, self.ENTITY_TYPE, obj)
        new_obj["local"] = self._client.is_local()
        self._update_attributes(new_obj)
        return self

    def refresh(self) -> Project:
        """
        Refresh object from backend.

        Returns
        -------
        Project
            Project object.
        """
        new_obj = read_entity_api_base(self._client, self.ENTITY_TYPE, self.name)
        new_obj["local"] = self._client.is_local()
        self._update_attributes(new_obj)
        return self

    def export(self, filename: str | None = None) -> None:
        """
        Export object as a YAML file. If the objects are not embedded, the objects are
        exported as a YAML file.

        Parameters
        ----------
        filename : str
            Name of the export YAML file. If not specified, the default value is used.

        Returns
        -------
        None
        """
        obj = self._refresh_to_dict()

        if filename is None:
            filename = f"{self.kind}_{self.name}.yml"
        pth = Path(self.spec.context) / filename
        pth.parent.mkdir(parents=True, exist_ok=True)
        write_yaml(pth, obj)

        for entity_type in CTX_ENTITIES:
            entity_list = obj.get("spec", {}).get(entity_type, [])
            if not entity_list:
                continue
            self._export_not_embedded(entity_list, entity_type)

    def _refresh_to_dict(self) -> dict:
        """
        Try to refresh object to collect entities related to project.

        Returns
        -------
        dict
            Entity object in dictionary format.
        """
        try:
            return self.refresh().to_dict()
        except BackendError:
            return self.to_dict()

    def _export_not_embedded(self, entity_list: list, entity_type: str) -> None:
        """
        Export project objects if not embedded.

        Parameters
        ----------
        entity_list : list
            Entity list.

        Returns
        -------
        None
        """
        for entity in entity_list:
            if not entity["metadata"]["embedded"]:
                obj: dict = read_entity_api_ctx(entity["key"])
                ent = FUNC_MAP[entity_type](obj)
                ent.export()

    #############################
    #  Artifacts
    #############################

    def new_artifact(
        self,
        name: str,
        kind: str,
        uuid: str | None = None,
        description: str | None = None,
        git_source: str | None = None,
        labels: list[str] | None = None,
        embedded: bool = True,
        path: str | None = None,
        src_path: str | None = None,
        **kwargs,
    ) -> Artifact:
        """
        Create an instance of the Artifact class with the provided parameters.

        Parameters
        ----------
        name : str
            Object name.
        kind : str
            Kind the object.
        uuid : str
            ID of the object (UUID4).
        description : str
            Description of the object (human readable).
        git_source : str
            Remote git source for object.
        labels : list[str]
            List of labels.
        embedded : bool
            Flag to determine if object must be embedded in project.
        path : str
            Object path on local file system or remote storage.
            If not provided, it's generated.
        src_path : str
            Local object path.
        **kwargs : dict
            Spec keyword arguments.

        Returns
        -------
        Artifact
            Object instance.
        """
        obj = new_artifact(
            project=self.name,
            name=name,
            kind=kind,
            uuid=uuid,
            description=description,
            git_source=git_source,
            labels=labels,
            embedded=embedded,
            path=path,
            src_path=src_path,
            **kwargs,
        )
        self.refresh()
        return obj

    def get_artifact(
        self,
        identifier: str,
        entity_id: str | None = None,
        **kwargs,
    ) -> Artifact:
        """
        Get object from backend.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        Artifact
            Instance of Artifact class.
        """
        obj = get_artifact(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            **kwargs,
        )
        self.refresh()
        return obj

    def delete_artifact(
        self,
        identifier: str,
        entity_id: str | None = None,
        delete_all_versions: bool = False,
        **kwargs,
    ) -> None:
        """
        Delete a Artifact from project.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        delete_all_versions : bool
            Delete all versions of the named entity.
            Use entity name instead of entity key as identifier.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        None
        """
        delete_artifact(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            delete_all_versions=delete_all_versions,
            **kwargs,
        )
        self.refresh()

    def list_artifacts(self, **kwargs) -> list[dict]:
        """
        List artifacts associated with the project.

        Parameters
        ----------
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        list[dict]
            List of objects related to project.
        """
        return list_artifacts(self.name, **kwargs)

    def log_artifact(
        self,
        name: str,
        kind: str,
        path: str | None = None,
        source_path: str | None = None,
        **kwargs,
    ) -> Artifact:
        """
        Create and upload an artifact.

        Parameters
        ----------
        name : str
            Object name.
        kind : str
            Kind the object.
        path : str
            Destination path of the artifact.
        source_path : str
            Artifact location on local machine.
        **kwargs : dict
            New artifact parameters.

        Returns
        -------
        Artifact
            Instance of Artifact class.
        """
        obj = log_artifact(
            project=self.name,
            name=name,
            kind=kind,
            path=path,
            source_path=source_path,
            **kwargs,
        )
        self.refresh()
        return obj

    #############################
    #  Functions
    #############################

    def new_function(
        self,
        name: str,
        kind: str,
        uuid: str | None = None,
        description: str | None = None,
        git_source: str | None = None,
        labels: list[str] | None = None,
        embedded: bool = True,
        **kwargs,
    ) -> Function:
        """
        Create a Function instance with the given parameters.

        Parameters
        ----------
        name : str
            Object name.
        kind : str
            Kind the object.
        uuid : str
            ID of the object (UUID4).
        description : str
            Description of the object (human readable).
        git_source : str
            Remote git source for object.
        labels : list[str]
            List of labels.
        embedded : bool
            Flag to determine if object must be embedded in project.
        **kwargs : dict
            Spec keyword arguments.

        Returns
        -------
        Function
            Object instance.
        """
        obj = new_function(
            project=self.name,
            name=name,
            kind=kind,
            uuid=uuid,
            description=description,
            git_source=git_source,
            labels=labels,
            embedded=embedded,
            **kwargs,
        )
        self.refresh()
        return obj

    def get_function(
        self,
        identifier: str,
        entity_id: str | None = None,
        **kwargs,
    ) -> Function:
        """
        Get object from backend.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        Function
            Instance of Function class.
        """
        obj = get_function(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            **kwargs,
        )
        self.refresh()
        return obj

    def delete_function(
        self,
        identifier: str,
        entity_id: str | None = None,
        delete_all_versions: bool = False,
        cascade: bool = False,
        **kwargs,
    ) -> None:
        """
        Delete a Function from project.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        delete_all_versions : bool
            Delete all versions of the named entity.
            Use entity name instead of entity key as identifier.
        cascade : bool
            Cascade delete.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        None
        """
        delete_function(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            delete_all_versions=delete_all_versions,
            cascade=cascade,
            **kwargs,
        )
        self.refresh()

    def list_functions(self, **kwargs) -> list[dict]:
        """
        List functions associated with the project.

        Parameters
        ----------
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        list[dict]
            List of objects related to project.
        """
        return list_functions(self.name, **kwargs)

    #############################
    #  Workflows
    #############################

    def new_workflow(
        self,
        name: str,
        kind: str,
        uuid: str | None = None,
        description: str | None = None,
        git_source: str | None = None,
        labels: list[str] | None = None,
        embedded: bool = True,
        **kwargs,
    ) -> Workflow:
        """
        Create a new Workflow instance with the specified parameters.

        Parameters
        ----------
        name : str
            Object name.
        uuid : str
            ID of the object (UUID4).
        description : str
            Description of the object (human readable).
        git_source : str
            Remote git source for object.
        labels : list[str]
            List of labels.
        embedded : bool
            Flag to determine if object must be embedded in project.
        **kwargs : dict
            Spec keyword arguments.

        Returns
        -------
        Workflow
            An instance of the created workflow.
        """
        obj = new_workflow(
            project=self.name,
            name=name,
            kind=kind,
            uuid=uuid,
            description=description,
            git_source=git_source,
            labels=labels,
            embedded=embedded,
            **kwargs,
        )
        self.refresh()
        return obj

    def get_workflow(
        self,
        identifier: str,
        entity_id: str | None = None,
        **kwargs,
    ) -> Workflow:
        """
        Get object from backend.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        Workflow
            Instance of Workflow class.
        """
        obj = get_workflow(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            **kwargs,
        )
        self.refresh()
        return obj

    def delete_workflow(
        self,
        identifier: str,
        entity_id: str | None = None,
        delete_all_versions: bool = False,
        cascade: bool = False,
        **kwargs,
    ) -> None:
        """
        Delete a Workflow from project.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        delete_all_versions : bool
            Delete all versions of the named entity.
            Use entity name instead of entity key as identifier.
        cascade : bool
            Cascade delete.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        None
        """
        delete_workflow(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            delete_all_versions=delete_all_versions,
            cascade=cascade,
            **kwargs,
        )
        self.refresh()

    def list_workflows(self, **kwargs) -> list[dict]:
        """
        List workflows associated with the project.

        Parameters
        ----------
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        list[dict]
            List of objects related to project.
        """
        return list_workflows(self.name, **kwargs)

    #############################
    #  Secrets
    #############################

    def new_secret(
        self,
        name: str,
        uuid: str | None = None,
        description: str | None = None,
        git_source: str | None = None,
        labels: list[str] | None = None,
        embedded: bool = True,
        secret_value: str | None = None,
        **kwargs,
    ) -> Secret:
        """
        Create a new Secret instance with the specified parameters.

        Parameters
        ----------
        name : str
            Object name.
        uuid : str
            ID of the object (UUID4).
        description : str
            Description of the object (human readable).
        git_source : str
            Remote git source for object.
        labels : list[str]
            List of labels.
        embedded : bool
            Flag to determine if object must be embedded in project.
        secret_value : str
            Value of the secret.
        **kwargs : dict
            Spec keyword arguments.

        Returns
        -------
        Secret
            An instance of the created secret.
        """
        obj = new_secret(
            project=self.name,
            name=name,
            uuid=uuid,
            description=description,
            git_source=git_source,
            labels=labels,
            embedded=embedded,
            secret_value=secret_value,
            **kwargs,
        )
        self.refresh()
        return obj

    def get_secret(
        self,
        identifier: str,
        entity_id: str | None = None,
        **kwargs,
    ) -> Secret:
        """
        Get object from backend.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        Secret
            Instance of Secret class.
        """
        obj = get_secret(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            **kwargs,
        )
        self.refresh()
        return obj

    def delete_secret(
        self,
        identifier: str,
        entity_id: str | None = None,
        delete_all_versions: bool = False,
        **kwargs,
    ) -> None:
        """
        Delete a Secret from project.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        delete_all_versions : bool
            Delete all versions of the named entity.
            Use entity name instead of entity key as identifier.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        None
        """
        delete_secret(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            delete_all_versions=delete_all_versions,
            **kwargs,
        )
        self.refresh()

    def list_secrets(self, **kwargs) -> list[dict]:
        """
        List secrets associated with the project.

        Parameters
        ----------
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        list[dict]
            List of objects related to project.
        """
        return list_secrets(self.name, **kwargs)

    #############################
    #  Static interface methods
    #############################

    @staticmethod
    def _parse_dict(obj: dict, validate: bool = True) -> dict:
        """
        Get dictionary and parse it to a valid entity dictionary.

        Parameters
        ----------
        entity : str
            Entity type.
        obj : dict
            Dictionary to parse.

        Returns
        -------
        dict
            A dictionary containing the attributes of the entity instance.
        """
        name = build_name(obj.get("name"))
        kind = obj.get("kind")
        metadata = build_metadata(kind, **obj.get("metadata", {}))
        spec = build_spec(kind, validate=validate, **obj.get("spec", {}))
        status = build_status(kind, **obj.get("status", {}))
        user = obj.get("user")
        local = obj.get("local", False)
        return {
            "name": name,
            "kind": kind,
            "metadata": metadata,
            "spec": spec,
            "status": status,
            "user": user,
            "local": local,
        }

__init__(name, kind, metadata, spec, status, user=None, local=False)

Constructor.

Parameters:

Name Type Description Default
name str

Name of the object.

required
kind str

Kind the object.

required
metadata Metadata

Metadata of the object.

required
spec ProjectSpec

Specification of the object.

required
status ProjectStatus

Status of the object.

required
user str

Owner of the object.

None
local bool

If True, export locally.

False
Source code in digitalhub_core/entities/projects/entity.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def __init__(
    self,
    name: str,
    kind: str,
    metadata: Metadata,
    spec: ProjectSpec,
    status: ProjectStatus,
    user: str | None = None,
    local: bool = False,
) -> None:
    """
    Constructor.

    Parameters
    ----------
    name : str
        Name of the object.
    kind : str
        Kind the object.
    metadata : Metadata
        Metadata of the object.
    spec : ProjectSpec
        Specification of the object.
    status : ProjectStatus
        Status of the object.
    user : str
        Owner of the object.
    local: bool
        If True, export locally.
    """
    super().__init__()
    self.id = name
    self.name = name
    self.kind = kind
    self.key = f"store://{name}"
    self.metadata = metadata
    self.spec = spec
    self.status = status
    self.user = user

    # Add attributes to be used in the to_dict method
    self._obj_attr.extend(["id", "name", "key"])

    # Set client
    self._client = get_client(local)

    # Set context
    set_context(self)

delete_artifact(identifier, entity_id=None, delete_all_versions=False, **kwargs)

Delete a Artifact from project.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
delete_all_versions bool

Delete all versions of the named entity. Use entity name instead of entity key as identifier.

False
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
None
Source code in digitalhub_core/entities/projects/entity.py
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
def delete_artifact(
    self,
    identifier: str,
    entity_id: str | None = None,
    delete_all_versions: bool = False,
    **kwargs,
) -> None:
    """
    Delete a Artifact from project.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    delete_all_versions : bool
        Delete all versions of the named entity.
        Use entity name instead of entity key as identifier.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    None
    """
    delete_artifact(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        delete_all_versions=delete_all_versions,
        **kwargs,
    )
    self.refresh()

delete_function(identifier, entity_id=None, delete_all_versions=False, cascade=False, **kwargs)

Delete a Function from project.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
delete_all_versions bool

Delete all versions of the named entity. Use entity name instead of entity key as identifier.

False
cascade bool

Cascade delete.

False
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
None
Source code in digitalhub_core/entities/projects/entity.py
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
def delete_function(
    self,
    identifier: str,
    entity_id: str | None = None,
    delete_all_versions: bool = False,
    cascade: bool = False,
    **kwargs,
) -> None:
    """
    Delete a Function from project.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    delete_all_versions : bool
        Delete all versions of the named entity.
        Use entity name instead of entity key as identifier.
    cascade : bool
        Cascade delete.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    None
    """
    delete_function(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        delete_all_versions=delete_all_versions,
        cascade=cascade,
        **kwargs,
    )
    self.refresh()

delete_secret(identifier, entity_id=None, delete_all_versions=False, **kwargs)

Delete a Secret from project.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
delete_all_versions bool

Delete all versions of the named entity. Use entity name instead of entity key as identifier.

False
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
None
Source code in digitalhub_core/entities/projects/entity.py
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
def delete_secret(
    self,
    identifier: str,
    entity_id: str | None = None,
    delete_all_versions: bool = False,
    **kwargs,
) -> None:
    """
    Delete a Secret from project.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    delete_all_versions : bool
        Delete all versions of the named entity.
        Use entity name instead of entity key as identifier.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    None
    """
    delete_secret(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        delete_all_versions=delete_all_versions,
        **kwargs,
    )
    self.refresh()

delete_workflow(identifier, entity_id=None, delete_all_versions=False, cascade=False, **kwargs)

Delete a Workflow from project.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
delete_all_versions bool

Delete all versions of the named entity. Use entity name instead of entity key as identifier.

False
cascade bool

Cascade delete.

False
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
None
Source code in digitalhub_core/entities/projects/entity.py
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
def delete_workflow(
    self,
    identifier: str,
    entity_id: str | None = None,
    delete_all_versions: bool = False,
    cascade: bool = False,
    **kwargs,
) -> None:
    """
    Delete a Workflow from project.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    delete_all_versions : bool
        Delete all versions of the named entity.
        Use entity name instead of entity key as identifier.
    cascade : bool
        Cascade delete.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    None
    """
    delete_workflow(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        delete_all_versions=delete_all_versions,
        cascade=cascade,
        **kwargs,
    )
    self.refresh()

export(filename=None)

Export object as a YAML file. If the objects are not embedded, the objects are exported as a YAML file.

Parameters:

Name Type Description Default
filename str

Name of the export YAML file. If not specified, the default value is used.

None

Returns:

Type Description
None
Source code in digitalhub_core/entities/projects/entity.py
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
def export(self, filename: str | None = None) -> None:
    """
    Export object as a YAML file. If the objects are not embedded, the objects are
    exported as a YAML file.

    Parameters
    ----------
    filename : str
        Name of the export YAML file. If not specified, the default value is used.

    Returns
    -------
    None
    """
    obj = self._refresh_to_dict()

    if filename is None:
        filename = f"{self.kind}_{self.name}.yml"
    pth = Path(self.spec.context) / filename
    pth.parent.mkdir(parents=True, exist_ok=True)
    write_yaml(pth, obj)

    for entity_type in CTX_ENTITIES:
        entity_list = obj.get("spec", {}).get(entity_type, [])
        if not entity_list:
            continue
        self._export_not_embedded(entity_list, entity_type)

get_artifact(identifier, entity_id=None, **kwargs)

Get object from backend.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
Artifact

Instance of Artifact class.

Source code in digitalhub_core/entities/projects/entity.py
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
def get_artifact(
    self,
    identifier: str,
    entity_id: str | None = None,
    **kwargs,
) -> Artifact:
    """
    Get object from backend.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    Artifact
        Instance of Artifact class.
    """
    obj = get_artifact(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        **kwargs,
    )
    self.refresh()
    return obj

get_function(identifier, entity_id=None, **kwargs)

Get object from backend.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
Function

Instance of Function class.

Source code in digitalhub_core/entities/projects/entity.py
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
def get_function(
    self,
    identifier: str,
    entity_id: str | None = None,
    **kwargs,
) -> Function:
    """
    Get object from backend.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    Function
        Instance of Function class.
    """
    obj = get_function(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        **kwargs,
    )
    self.refresh()
    return obj

get_secret(identifier, entity_id=None, **kwargs)

Get object from backend.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
Secret

Instance of Secret class.

Source code in digitalhub_core/entities/projects/entity.py
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
def get_secret(
    self,
    identifier: str,
    entity_id: str | None = None,
    **kwargs,
) -> Secret:
    """
    Get object from backend.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    Secret
        Instance of Secret class.
    """
    obj = get_secret(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        **kwargs,
    )
    self.refresh()
    return obj

get_workflow(identifier, entity_id=None, **kwargs)

Get object from backend.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
Workflow

Instance of Workflow class.

Source code in digitalhub_core/entities/projects/entity.py
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
def get_workflow(
    self,
    identifier: str,
    entity_id: str | None = None,
    **kwargs,
) -> Workflow:
    """
    Get object from backend.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    Workflow
        Instance of Workflow class.
    """
    obj = get_workflow(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        **kwargs,
    )
    self.refresh()
    return obj

list_artifacts(**kwargs)

List artifacts associated with the project.

Parameters:

Name Type Description Default
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[dict]

List of objects related to project.

Source code in digitalhub_core/entities/projects/entity.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
def list_artifacts(self, **kwargs) -> list[dict]:
    """
    List artifacts associated with the project.

    Parameters
    ----------
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    list[dict]
        List of objects related to project.
    """
    return list_artifacts(self.name, **kwargs)

list_functions(**kwargs)

List functions associated with the project.

Parameters:

Name Type Description Default
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[dict]

List of objects related to project.

Source code in digitalhub_core/entities/projects/entity.py
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
def list_functions(self, **kwargs) -> list[dict]:
    """
    List functions associated with the project.

    Parameters
    ----------
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    list[dict]
        List of objects related to project.
    """
    return list_functions(self.name, **kwargs)

list_secrets(**kwargs)

List secrets associated with the project.

Parameters:

Name Type Description Default
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[dict]

List of objects related to project.

Source code in digitalhub_core/entities/projects/entity.py
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
def list_secrets(self, **kwargs) -> list[dict]:
    """
    List secrets associated with the project.

    Parameters
    ----------
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    list[dict]
        List of objects related to project.
    """
    return list_secrets(self.name, **kwargs)

list_workflows(**kwargs)

List workflows associated with the project.

Parameters:

Name Type Description Default
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[dict]

List of objects related to project.

Source code in digitalhub_core/entities/projects/entity.py
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
def list_workflows(self, **kwargs) -> list[dict]:
    """
    List workflows associated with the project.

    Parameters
    ----------
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    list[dict]
        List of objects related to project.
    """
    return list_workflows(self.name, **kwargs)

log_artifact(name, kind, path=None, source_path=None, **kwargs)

Create and upload an artifact.

Parameters:

Name Type Description Default
name str

Object name.

required
kind str

Kind the object.

required
path str

Destination path of the artifact.

None
source_path str

Artifact location on local machine.

None
**kwargs dict

New artifact parameters.

{}

Returns:

Type Description
Artifact

Instance of Artifact class.

Source code in digitalhub_core/entities/projects/entity.py
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
def log_artifact(
    self,
    name: str,
    kind: str,
    path: str | None = None,
    source_path: str | None = None,
    **kwargs,
) -> Artifact:
    """
    Create and upload an artifact.

    Parameters
    ----------
    name : str
        Object name.
    kind : str
        Kind the object.
    path : str
        Destination path of the artifact.
    source_path : str
        Artifact location on local machine.
    **kwargs : dict
        New artifact parameters.

    Returns
    -------
    Artifact
        Instance of Artifact class.
    """
    obj = log_artifact(
        project=self.name,
        name=name,
        kind=kind,
        path=path,
        source_path=source_path,
        **kwargs,
    )
    self.refresh()
    return obj

new_artifact(name, kind, uuid=None, description=None, git_source=None, labels=None, embedded=True, path=None, src_path=None, **kwargs)

Create an instance of the Artifact class with the provided parameters.

Parameters:

Name Type Description Default
name str

Object name.

required
kind str

Kind the object.

required
uuid str

ID of the object (UUID4).

None
description str

Description of the object (human readable).

None
git_source str

Remote git source for object.

None
labels list[str]

List of labels.

None
embedded bool

Flag to determine if object must be embedded in project.

True
path str

Object path on local file system or remote storage. If not provided, it's generated.

None
src_path str

Local object path.

None
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Artifact

Object instance.

Source code in digitalhub_core/entities/projects/entity.py
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
def new_artifact(
    self,
    name: str,
    kind: str,
    uuid: str | None = None,
    description: str | None = None,
    git_source: str | None = None,
    labels: list[str] | None = None,
    embedded: bool = True,
    path: str | None = None,
    src_path: str | None = None,
    **kwargs,
) -> Artifact:
    """
    Create an instance of the Artifact class with the provided parameters.

    Parameters
    ----------
    name : str
        Object name.
    kind : str
        Kind the object.
    uuid : str
        ID of the object (UUID4).
    description : str
        Description of the object (human readable).
    git_source : str
        Remote git source for object.
    labels : list[str]
        List of labels.
    embedded : bool
        Flag to determine if object must be embedded in project.
    path : str
        Object path on local file system or remote storage.
        If not provided, it's generated.
    src_path : str
        Local object path.
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    Artifact
        Object instance.
    """
    obj = new_artifact(
        project=self.name,
        name=name,
        kind=kind,
        uuid=uuid,
        description=description,
        git_source=git_source,
        labels=labels,
        embedded=embedded,
        path=path,
        src_path=src_path,
        **kwargs,
    )
    self.refresh()
    return obj

new_function(name, kind, uuid=None, description=None, git_source=None, labels=None, embedded=True, **kwargs)

Create a Function instance with the given parameters.

Parameters:

Name Type Description Default
name str

Object name.

required
kind str

Kind the object.

required
uuid str

ID of the object (UUID4).

None
description str

Description of the object (human readable).

None
git_source str

Remote git source for object.

None
labels list[str]

List of labels.

None
embedded bool

Flag to determine if object must be embedded in project.

True
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Function

Object instance.

Source code in digitalhub_core/entities/projects/entity.py
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
def new_function(
    self,
    name: str,
    kind: str,
    uuid: str | None = None,
    description: str | None = None,
    git_source: str | None = None,
    labels: list[str] | None = None,
    embedded: bool = True,
    **kwargs,
) -> Function:
    """
    Create a Function instance with the given parameters.

    Parameters
    ----------
    name : str
        Object name.
    kind : str
        Kind the object.
    uuid : str
        ID of the object (UUID4).
    description : str
        Description of the object (human readable).
    git_source : str
        Remote git source for object.
    labels : list[str]
        List of labels.
    embedded : bool
        Flag to determine if object must be embedded in project.
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    Function
        Object instance.
    """
    obj = new_function(
        project=self.name,
        name=name,
        kind=kind,
        uuid=uuid,
        description=description,
        git_source=git_source,
        labels=labels,
        embedded=embedded,
        **kwargs,
    )
    self.refresh()
    return obj

new_secret(name, uuid=None, description=None, git_source=None, labels=None, embedded=True, secret_value=None, **kwargs)

Create a new Secret instance with the specified parameters.

Parameters:

Name Type Description Default
name str

Object name.

required
uuid str

ID of the object (UUID4).

None
description str

Description of the object (human readable).

None
git_source str

Remote git source for object.

None
labels list[str]

List of labels.

None
embedded bool

Flag to determine if object must be embedded in project.

True
secret_value str

Value of the secret.

None
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Secret

An instance of the created secret.

Source code in digitalhub_core/entities/projects/entity.py
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
def new_secret(
    self,
    name: str,
    uuid: str | None = None,
    description: str | None = None,
    git_source: str | None = None,
    labels: list[str] | None = None,
    embedded: bool = True,
    secret_value: str | None = None,
    **kwargs,
) -> Secret:
    """
    Create a new Secret instance with the specified parameters.

    Parameters
    ----------
    name : str
        Object name.
    uuid : str
        ID of the object (UUID4).
    description : str
        Description of the object (human readable).
    git_source : str
        Remote git source for object.
    labels : list[str]
        List of labels.
    embedded : bool
        Flag to determine if object must be embedded in project.
    secret_value : str
        Value of the secret.
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    Secret
        An instance of the created secret.
    """
    obj = new_secret(
        project=self.name,
        name=name,
        uuid=uuid,
        description=description,
        git_source=git_source,
        labels=labels,
        embedded=embedded,
        secret_value=secret_value,
        **kwargs,
    )
    self.refresh()
    return obj

new_workflow(name, kind, uuid=None, description=None, git_source=None, labels=None, embedded=True, **kwargs)

Create a new Workflow instance with the specified parameters.

Parameters:

Name Type Description Default
name str

Object name.

required
uuid str

ID of the object (UUID4).

None
description str

Description of the object (human readable).

None
git_source str

Remote git source for object.

None
labels list[str]

List of labels.

None
embedded bool

Flag to determine if object must be embedded in project.

True
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Workflow

An instance of the created workflow.

Source code in digitalhub_core/entities/projects/entity.py
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
def new_workflow(
    self,
    name: str,
    kind: str,
    uuid: str | None = None,
    description: str | None = None,
    git_source: str | None = None,
    labels: list[str] | None = None,
    embedded: bool = True,
    **kwargs,
) -> Workflow:
    """
    Create a new Workflow instance with the specified parameters.

    Parameters
    ----------
    name : str
        Object name.
    uuid : str
        ID of the object (UUID4).
    description : str
        Description of the object (human readable).
    git_source : str
        Remote git source for object.
    labels : list[str]
        List of labels.
    embedded : bool
        Flag to determine if object must be embedded in project.
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    Workflow
        An instance of the created workflow.
    """
    obj = new_workflow(
        project=self.name,
        name=name,
        kind=kind,
        uuid=uuid,
        description=description,
        git_source=git_source,
        labels=labels,
        embedded=embedded,
        **kwargs,
    )
    self.refresh()
    return obj

refresh()

Refresh object from backend.

Returns:

Type Description
Project

Project object.

Source code in digitalhub_core/entities/projects/entity.py
170
171
172
173
174
175
176
177
178
179
180
181
182
def refresh(self) -> Project:
    """
    Refresh object from backend.

    Returns
    -------
    Project
        Project object.
    """
    new_obj = read_entity_api_base(self._client, self.ENTITY_TYPE, self.name)
    new_obj["local"] = self._client.is_local()
    self._update_attributes(new_obj)
    return self

save(update=False)

Save entity into backend.

Parameters:

Name Type Description Default
update bool

If True, the object will be updated.

False

Returns:

Type Description
Project

Entity saved.

Source code in digitalhub_core/entities/projects/entity.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
def save(self, update: bool = False) -> Project:
    """
    Save entity into backend.

    Parameters
    ----------
    update : bool
        If True, the object will be updated.

    Returns
    -------
    Project
        Entity saved.
    """
    obj = self._refresh_to_dict()

    if not update:
        new_obj = create_entity_api_base(self._client, self.ENTITY_TYPE, obj)
        new_obj["local"] = self._client.is_local()
        self._update_attributes(new_obj)
        return self

    self.metadata.updated = obj["metadata"]["updated"] = get_timestamp()
    new_obj = update_entity_api_base(self._client, self.ENTITY_TYPE, obj)
    new_obj["local"] = self._client.is_local()
    self._update_attributes(new_obj)
    return self

project_from_dict(obj)

Create project from dictionary.

Parameters:

Name Type Description Default
obj dict

Dictionary to create object from.

required

Returns:

Type Description
Project

Project object.

Source code in digitalhub_core/entities/projects/entity.py
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
def project_from_dict(obj: dict) -> Project:
    """
    Create project from dictionary.

    Parameters
    ----------
    obj : dict
        Dictionary to create object from.

    Returns
    -------
    Project
        Project object.
    """
    return Project.from_dict(obj)

project_from_parameters(name, kind, description=None, git_source=None, labels=None, local=False, context=None, **kwargs)

Create project.

Parameters:

Name Type Description Default
name str

Object name.

required
kind str

Kind the object.

required
description str

Description of the object (human readable).

None
git_source str

Remote git source for object.

None
labels list[str]

List of labels.

None
local bool

Flag to determine if object will be exported to backend.

False
context str

The context of the project.

None
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Project

Project object.

Source code in digitalhub_core/entities/projects/entity.py
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
def project_from_parameters(
    name: str,
    kind: str,
    description: str | None = None,
    git_source: str | None = None,
    labels: list[str] | None = None,
    local: bool = False,
    context: str | None = None,
    **kwargs,
) -> Project:
    """
    Create project.

    Parameters
    ----------
    name : str
        Object name.
    kind : str
        Kind the object.
    description : str
        Description of the object (human readable).
    git_source : str
        Remote git source for object.
    labels : list[str]
        List of labels.
    local : bool
        Flag to determine if object will be exported to backend.
    context : str
        The context of the project.
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    Project
        Project object.
    """
    name = build_name(name)
    spec = build_spec(
        kind,
        context=context,
        **kwargs,
    )
    metadata = build_metadata(
        kind,
        project=name,
        name=name,
        description=description,
        labels=labels,
        source=git_source,
    )
    status = build_status(kind)
    return Project(
        name=name,
        kind=kind,
        metadata=metadata,
        spec=spec,
        status=status,
        local=local,
    )

ProjectData

Bases: Project

ProjectData class.

Source code in digitalhub_data/entities/projects/entity.py
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
class ProjectData(Project):

    """
    ProjectData class.
    """

    #############################
    #  Dataitems
    #############################

    def new_dataitem(
        self,
        name: str,
        kind: str,
        uuid: str | None = None,
        description: str | None = None,
        git_source: str | None = None,
        labels: list[str] | None = None,
        embedded: bool = True,
        path: str | None = None,
        **kwargs,
    ) -> Dataitem:
        """
        Create a new object instance.

        Parameters
        ----------
        name : str
            Object name.
        kind : str
            Kind the object.
        uuid : str
            ID of the object (UUID4).
        description : str
            Description of the object (human readable).
        git_source : str
            Remote git source for object.
        labels : list[str]
            List of labels.
        embedded : bool
            Flag to determine if object must be embedded in project.
        path : str
            Object path on local file system or remote storage.
            If not provided, it's generated.
        **kwargs : dict
            Spec keyword arguments.

        Returns
        -------
        Dataitem
            Object instance.
        """
        obj = new_dataitem(
            project=self.name,
            name=name,
            kind=kind,
            path=path,
            uuid=uuid,
            description=description,
            git_source=git_source,
            labels=labels,
            embedded=embedded,
            **kwargs,
        )
        self.refresh()
        return obj

    def get_dataitem(
        self,
        identifier: str,
        entity_id: str | None = None,
        **kwargs,
    ) -> Dataitem:
        """
        Get object from backend.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        Dataitem
            Instance of Dataitem class.
        """
        obj = get_dataitem(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            **kwargs,
        )
        self.refresh()
        return obj

    def delete_dataitem(
        self,
        identifier: str,
        entity_id: str | None = None,
        delete_all_versions: bool = False,
        **kwargs,
    ) -> None:
        """
        Delete a Dataitem from project.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        delete_all_versions : bool
            Delete all versions of the named entity.
            Use entity name instead of entity key as identifier.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        None
        """
        delete_dataitem(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            delete_all_versions=delete_all_versions,
            **kwargs,
        )
        self.refresh()

    def list_dataitems(self, **kwargs) -> list[dict]:
        """
        List dataitems associated with the project.

        Parameters
        ----------
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        list[dict]
            List of objects related to project.
        """
        return list_dataitems(self.name, **kwargs)

    def log_dataitem(
        self,
        name: str,
        kind: str,
        path: str | None = None,
        data: Any | None = None,
        extension: str | None = None,
        **kwargs,
    ) -> Dataitem:
        """
        Log a dataitem to the project.

        Parameters
        ----------
        name : str
            Object name.
        kind : str
            Kind the object.
        path : str
            Destination path of the dataitem.
        data : Any
            Dataframe to log.
        extension : str
            Extension of the dataitem.
        **kwargs : dict
            New dataitem parameters.

        Returns
        -------
        Dataitem
            Object instance.
        """
        obj = log_dataitem(
            project=self.name,
            name=name,
            kind=kind,
            path=path,
            data=data,
            extension=extension,
            **kwargs,
        )
        self.refresh()
        return obj

    @staticmethod
    def _parse_dict(obj: dict, validate: bool = True) -> dict:
        """
        Get dictionary and parse it to a valid entity dictionary.

        Parameters
        ----------
        entity : str
            Entity type.
        obj : dict
            Dictionary to parse.

        Returns
        -------
        dict
            A dictionary containing the attributes of the entity instance.
        """
        # Override methods to search in digitalhub_data
        name = build_name(obj.get("name"))
        kind = obj.get("kind")
        metadata = build_metadata(kind, **obj.get("metadata", {}))
        spec = build_spec(kind, validate=validate, **obj.get("spec", {}))
        status = build_status(kind, **obj.get("status", {}))
        user = obj.get("user")
        local = obj.get("local", False)
        return {
            "name": name,
            "kind": kind,
            "metadata": metadata,
            "spec": spec,
            "status": status,
            "user": user,
            "local": local,
        }

delete_dataitem(identifier, entity_id=None, delete_all_versions=False, **kwargs)

Delete a Dataitem from project.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
delete_all_versions bool

Delete all versions of the named entity. Use entity name instead of entity key as identifier.

False
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
None
Source code in digitalhub_data/entities/projects/entity.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
def delete_dataitem(
    self,
    identifier: str,
    entity_id: str | None = None,
    delete_all_versions: bool = False,
    **kwargs,
) -> None:
    """
    Delete a Dataitem from project.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    delete_all_versions : bool
        Delete all versions of the named entity.
        Use entity name instead of entity key as identifier.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    None
    """
    delete_dataitem(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        delete_all_versions=delete_all_versions,
        **kwargs,
    )
    self.refresh()

get_dataitem(identifier, entity_id=None, **kwargs)

Get object from backend.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
Dataitem

Instance of Dataitem class.

Source code in digitalhub_data/entities/projects/entity.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def get_dataitem(
    self,
    identifier: str,
    entity_id: str | None = None,
    **kwargs,
) -> Dataitem:
    """
    Get object from backend.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    Dataitem
        Instance of Dataitem class.
    """
    obj = get_dataitem(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        **kwargs,
    )
    self.refresh()
    return obj

list_dataitems(**kwargs)

List dataitems associated with the project.

Parameters:

Name Type Description Default
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[dict]

List of objects related to project.

Source code in digitalhub_data/entities/projects/entity.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
def list_dataitems(self, **kwargs) -> list[dict]:
    """
    List dataitems associated with the project.

    Parameters
    ----------
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    list[dict]
        List of objects related to project.
    """
    return list_dataitems(self.name, **kwargs)

log_dataitem(name, kind, path=None, data=None, extension=None, **kwargs)

Log a dataitem to the project.

Parameters:

Name Type Description Default
name str

Object name.

required
kind str

Kind the object.

required
path str

Destination path of the dataitem.

None
data Any

Dataframe to log.

None
extension str

Extension of the dataitem.

None
**kwargs dict

New dataitem parameters.

{}

Returns:

Type Description
Dataitem

Object instance.

Source code in digitalhub_data/entities/projects/entity.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def log_dataitem(
    self,
    name: str,
    kind: str,
    path: str | None = None,
    data: Any | None = None,
    extension: str | None = None,
    **kwargs,
) -> Dataitem:
    """
    Log a dataitem to the project.

    Parameters
    ----------
    name : str
        Object name.
    kind : str
        Kind the object.
    path : str
        Destination path of the dataitem.
    data : Any
        Dataframe to log.
    extension : str
        Extension of the dataitem.
    **kwargs : dict
        New dataitem parameters.

    Returns
    -------
    Dataitem
        Object instance.
    """
    obj = log_dataitem(
        project=self.name,
        name=name,
        kind=kind,
        path=path,
        data=data,
        extension=extension,
        **kwargs,
    )
    self.refresh()
    return obj

new_dataitem(name, kind, uuid=None, description=None, git_source=None, labels=None, embedded=True, path=None, **kwargs)

Create a new object instance.

Parameters:

Name Type Description Default
name str

Object name.

required
kind str

Kind the object.

required
uuid str

ID of the object (UUID4).

None
description str

Description of the object (human readable).

None
git_source str

Remote git source for object.

None
labels list[str]

List of labels.

None
embedded bool

Flag to determine if object must be embedded in project.

True
path str

Object path on local file system or remote storage. If not provided, it's generated.

None
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Dataitem

Object instance.

Source code in digitalhub_data/entities/projects/entity.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def new_dataitem(
    self,
    name: str,
    kind: str,
    uuid: str | None = None,
    description: str | None = None,
    git_source: str | None = None,
    labels: list[str] | None = None,
    embedded: bool = True,
    path: str | None = None,
    **kwargs,
) -> Dataitem:
    """
    Create a new object instance.

    Parameters
    ----------
    name : str
        Object name.
    kind : str
        Kind the object.
    uuid : str
        ID of the object (UUID4).
    description : str
        Description of the object (human readable).
    git_source : str
        Remote git source for object.
    labels : list[str]
        List of labels.
    embedded : bool
        Flag to determine if object must be embedded in project.
    path : str
        Object path on local file system or remote storage.
        If not provided, it's generated.
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    Dataitem
        Object instance.
    """
    obj = new_dataitem(
        project=self.name,
        name=name,
        kind=kind,
        path=path,
        uuid=uuid,
        description=description,
        git_source=git_source,
        labels=labels,
        embedded=embedded,
        **kwargs,
    )
    self.refresh()
    return obj

project_from_dict(obj)

Create project from dictionary.

Parameters:

Name Type Description Default
obj dict

Dictionary to create object from.

required

Returns:

Type Description
ProjectData

ProjectData object.

Source code in digitalhub_data/entities/projects/entity.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
def project_from_dict(obj: dict) -> ProjectData:
    """
    Create project from dictionary.

    Parameters
    ----------
    obj : dict
        Dictionary to create object from.

    Returns
    -------
    ProjectData
        ProjectData object.
    """
    return ProjectData.from_dict(obj)

project_from_parameters(name, kind, description=None, git_source=None, labels=None, local=False, context=None, **kwargs)

Create project.

Parameters:

Name Type Description Default
name str

Object name.

required
kind str

Kind the object.

required
description str

Description of the object (human readable).

None
git_source str

Remote git source for object.

None
labels list[str]

List of labels.

None
local bool

Flag to determine if object will be exported to backend.

False
context str

The context of the project.

None
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
ProjectData

ProjectData object.

Source code in digitalhub_data/entities/projects/entity.py
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
def project_from_parameters(
    name: str,
    kind: str,
    description: str | None = None,
    git_source: str | None = None,
    labels: list[str] | None = None,
    local: bool = False,
    context: str | None = None,
    **kwargs,
) -> ProjectData:
    """
    Create project.

    Parameters
    ----------
    name : str
        Object name.
    kind : str
        Kind the object.
    description : str
        Description of the object (human readable).
    git_source : str
        Remote git source for object.
    labels : list[str]
        List of labels.
    local : bool
        Flag to determine if object will be exported to backend.
    context : str
        The context of the project.
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    ProjectData
        ProjectData object.
    """
    name = build_name(name)
    spec = build_spec(
        kind,
        context=context,
        **kwargs,
    )
    metadata = build_metadata(
        kind,
        project=name,
        name=name,
        description=description,
        labels=labels,
        source=git_source,
    )
    status = build_status(kind)
    return ProjectData(
        name=name,
        kind=kind,
        metadata=metadata,
        spec=spec,
        status=status,
        local=local,
    )

ProjectMl

Bases: ProjectData

ProjectMl class.

Source code in digitalhub_ml/entities/projects/entity.py
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
class ProjectMl(ProjectData):
    """
    ProjectMl class.
    """

    #############################
    #  Models
    #############################

    def new_model(
        self,
        name: str,
        kind: str,
        uuid: str | None = None,
        description: str | None = None,
        git_source: str | None = None,
        labels: list[str] | None = None,
        embedded: bool = True,
        path: str | None = None,
        framework: str | None = None,
        algorithm: str | None = None,
        **kwargs,
    ) -> Model:
        """
        Create a new Model instance with the specified parameters.

        Parameters
        ----------
        name : str
            Object name.
        kind : str
            Kind the object.
        uuid : str
            ID of the object (UUID4).
        description : str
            Description of the object (human readable).
        git_source : str
            Remote git source for object.
        labels : list[str]
            List of labels.
        embedded : bool
            Flag to determine if object must be embedded in project.
        path : str
            Object path on local file system or remote storage.
            If not provided, it's generated.
        framework : str
            Model framework (e.g. 'pytorch').
        algorithm : str
            Model algorithm (e.g. 'resnet').
        **kwargs : dict
            Spec keyword arguments.

        Returns
        -------
        Model
            An instance of the created model.
        """
        obj = new_model(
            project=self.name,
            name=name,
            kind=kind,
            uuid=uuid,
            description=description,
            git_source=git_source,
            labels=labels,
            embedded=embedded,
            path=path,
            framework=framework,
            algorithm=algorithm,
            **kwargs,
        )
        self.refresh()
        return obj

    def get_model(
        self,
        identifier: str,
        entity_id: str | None = None,
        **kwargs,
    ) -> Model:
        """
        Get object from backend.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        Model
            Instance of Model class.
        """
        obj = get_model(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            **kwargs,
        )
        self.refresh()
        return obj

    def delete_model(
        self,
        identifier: str,
        entity_id: str | None = None,
        delete_all_versions: bool = False,
        **kwargs,
    ) -> None:
        """
        Delete a Model from project.

        Parameters
        ----------
        identifier : str
            Entity key or name.
        entity_id : str
            Entity ID.
        delete_all_versions : bool
            Delete all versions of the named entity.
            Use entity name instead of entity key as identifier.
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        None
        """
        delete_model(
            identifier=identifier,
            project=self.name,
            entity_id=entity_id,
            delete_all_versions=delete_all_versions,
            **kwargs,
        )
        self.refresh()

    def list_models(self, **kwargs) -> list[dict]:
        """
        List models associated with the project.

        Parameters
        ----------
        **kwargs : dict
            Parameters to pass to the API call.

        Returns
        -------
        list[dict]
            List of objects related to project.
        """
        return list_models(self.name, **kwargs)

    def log_model(
        self,
        name: str,
        kind: str,
        path: str | None = None,
        source_path: str | None = None,
        **kwargs,
    ) -> Model:
        """
        Create and upload an model.

        Parameters
        ----------
        name : str
            Object name.
        kind : str
            Kind the object.
        path : str
            Destination path of the model.
        source_path : str
            Model location on local machine.
        **kwargs : dict
            New model parameters.

        Returns
        -------
        Model
            Instance of Model class.
        """
        obj = log_model(
            project=self.name,
            name=name,
            kind=kind,
            path=path,
            source_path=source_path,
            **kwargs,
        )
        self.refresh()
        return obj

    @staticmethod
    def _parse_dict(obj: dict, validate: bool = True) -> dict:
        """
        Get dictionary and parse it to a valid entity dictionary.

        Parameters
        ----------
        entity : str
            Entity type.
        obj : dict
            Dictionary to parse.

        Returns
        -------
        dict
            A dictionary containing the attributes of the entity instance.
        """
        # Override methods to search in digitalhub_ml
        name = build_name(obj.get("name"))
        kind = obj.get("kind")
        metadata = build_metadata(kind, **obj.get("metadata", {}))
        spec = build_spec(kind, validate=validate, **obj.get("spec", {}))
        status = build_status(kind, **obj.get("status", {}))
        user = obj.get("user")
        local = obj.get("local", False)
        return {
            "name": name,
            "kind": kind,
            "metadata": metadata,
            "spec": spec,
            "status": status,
            "user": user,
            "local": local,
        }

delete_model(identifier, entity_id=None, delete_all_versions=False, **kwargs)

Delete a Model from project.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
delete_all_versions bool

Delete all versions of the named entity. Use entity name instead of entity key as identifier.

False
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
None
Source code in digitalhub_ml/entities/projects/entity.py
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
def delete_model(
    self,
    identifier: str,
    entity_id: str | None = None,
    delete_all_versions: bool = False,
    **kwargs,
) -> None:
    """
    Delete a Model from project.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    delete_all_versions : bool
        Delete all versions of the named entity.
        Use entity name instead of entity key as identifier.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    None
    """
    delete_model(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        delete_all_versions=delete_all_versions,
        **kwargs,
    )
    self.refresh()

get_model(identifier, entity_id=None, **kwargs)

Get object from backend.

Parameters:

Name Type Description Default
identifier str

Entity key or name.

required
entity_id str

Entity ID.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
Model

Instance of Model class.

Source code in digitalhub_ml/entities/projects/entity.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def get_model(
    self,
    identifier: str,
    entity_id: str | None = None,
    **kwargs,
) -> Model:
    """
    Get object from backend.

    Parameters
    ----------
    identifier : str
        Entity key or name.
    entity_id : str
        Entity ID.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    Model
        Instance of Model class.
    """
    obj = get_model(
        identifier=identifier,
        project=self.name,
        entity_id=entity_id,
        **kwargs,
    )
    self.refresh()
    return obj

list_models(**kwargs)

List models associated with the project.

Parameters:

Name Type Description Default
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[dict]

List of objects related to project.

Source code in digitalhub_ml/entities/projects/entity.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
def list_models(self, **kwargs) -> list[dict]:
    """
    List models associated with the project.

    Parameters
    ----------
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    list[dict]
        List of objects related to project.
    """
    return list_models(self.name, **kwargs)

log_model(name, kind, path=None, source_path=None, **kwargs)

Create and upload an model.

Parameters:

Name Type Description Default
name str

Object name.

required
kind str

Kind the object.

required
path str

Destination path of the model.

None
source_path str

Model location on local machine.

None
**kwargs dict

New model parameters.

{}

Returns:

Type Description
Model

Instance of Model class.

Source code in digitalhub_ml/entities/projects/entity.py
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def log_model(
    self,
    name: str,
    kind: str,
    path: str | None = None,
    source_path: str | None = None,
    **kwargs,
) -> Model:
    """
    Create and upload an model.

    Parameters
    ----------
    name : str
        Object name.
    kind : str
        Kind the object.
    path : str
        Destination path of the model.
    source_path : str
        Model location on local machine.
    **kwargs : dict
        New model parameters.

    Returns
    -------
    Model
        Instance of Model class.
    """
    obj = log_model(
        project=self.name,
        name=name,
        kind=kind,
        path=path,
        source_path=source_path,
        **kwargs,
    )
    self.refresh()
    return obj

new_model(name, kind, uuid=None, description=None, git_source=None, labels=None, embedded=True, path=None, framework=None, algorithm=None, **kwargs)

Create a new Model instance with the specified parameters.

Parameters:

Name Type Description Default
name str

Object name.

required
kind str

Kind the object.

required
uuid str

ID of the object (UUID4).

None
description str

Description of the object (human readable).

None
git_source str

Remote git source for object.

None
labels list[str]

List of labels.

None
embedded bool

Flag to determine if object must be embedded in project.

True
path str

Object path on local file system or remote storage. If not provided, it's generated.

None
framework str

Model framework (e.g. 'pytorch').

None
algorithm str

Model algorithm (e.g. 'resnet').

None
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Model

An instance of the created model.

Source code in digitalhub_ml/entities/projects/entity.py
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def new_model(
    self,
    name: str,
    kind: str,
    uuid: str | None = None,
    description: str | None = None,
    git_source: str | None = None,
    labels: list[str] | None = None,
    embedded: bool = True,
    path: str | None = None,
    framework: str | None = None,
    algorithm: str | None = None,
    **kwargs,
) -> Model:
    """
    Create a new Model instance with the specified parameters.

    Parameters
    ----------
    name : str
        Object name.
    kind : str
        Kind the object.
    uuid : str
        ID of the object (UUID4).
    description : str
        Description of the object (human readable).
    git_source : str
        Remote git source for object.
    labels : list[str]
        List of labels.
    embedded : bool
        Flag to determine if object must be embedded in project.
    path : str
        Object path on local file system or remote storage.
        If not provided, it's generated.
    framework : str
        Model framework (e.g. 'pytorch').
    algorithm : str
        Model algorithm (e.g. 'resnet').
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    Model
        An instance of the created model.
    """
    obj = new_model(
        project=self.name,
        name=name,
        kind=kind,
        uuid=uuid,
        description=description,
        git_source=git_source,
        labels=labels,
        embedded=embedded,
        path=path,
        framework=framework,
        algorithm=algorithm,
        **kwargs,
    )
    self.refresh()
    return obj

project_from_dict(obj)

Create project from dictionary.

Parameters:

Name Type Description Default
obj dict

Dictionary to create object from.

required

Returns:

Type Description
ProjectData

ProjectData object.

Source code in digitalhub_ml/entities/projects/entity.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
def project_from_dict(obj: dict) -> ProjectData:
    """
    Create project from dictionary.

    Parameters
    ----------
    obj : dict
        Dictionary to create object from.

    Returns
    -------
    ProjectData
        ProjectData object.
    """
    return ProjectMl.from_dict(obj)

project_from_parameters(name, kind, description=None, git_source=None, labels=None, local=False, context=None, **kwargs)

Create project.

Parameters:

Name Type Description Default
name str

Object name.

required
kind str

Kind the object.

required
description str

Description of the object (human readable).

None
git_source str

Remote git source for object.

None
labels list[str]

List of labels.

None
local bool

Flag to determine if object will be exported to backend.

False
context str

The context of the project.

None
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
ProjectData

ProjectData object.

Source code in digitalhub_ml/entities/projects/entity.py
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
def project_from_parameters(
    name: str,
    kind: str,
    description: str | None = None,
    git_source: str | None = None,
    labels: list[str] | None = None,
    local: bool = False,
    context: str | None = None,
    **kwargs,
) -> ProjectData:
    """
    Create project.

    Parameters
    ----------
    name : str
        Object name.
    kind : str
        Kind the object.
    description : str
        Description of the object (human readable).
    git_source : str
        Remote git source for object.
    labels : list[str]
        List of labels.
    local : bool
        Flag to determine if object will be exported to backend.
    context : str
        The context of the project.
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    ProjectData
        ProjectData object.
    """
    name = build_name(name)
    spec = build_spec(
        kind,
        context=context,
        **kwargs,
    )
    metadata = build_metadata(
        kind,
        project=name,
        name=name,
        description=description,
        labels=labels,
        source=git_source,
    )
    status = build_status(kind)
    return ProjectMl(
        name=name,
        kind=kind,
        metadata=metadata,
        spec=spec,
        status=status,
        local=local,
    )