Skip to content

CRUD

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

Delete object from backend.

Parameters:

Name Type Description Default
identifier str

Entity key (store://...) or entity name.

required
project str

Project name.

None
entity_id str

Entity ID.

None
delete_all_versions bool

Delete all versions of the named entity. If True, use entity name instead of entity key as identifier.

False
cascade bool

Cascade delete.

True
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
dict

Response from backend.

Examples:

If delete_all_versions is False:

>>> obj = delete_workflow("store://my-workflow-key")

Otherwise:

>>> obj = delete_workflow("workflow-name",
>>>                       project="my-project",
>>>                       delete_all_versions=True)
Source code in digitalhub_core/entities/workflow/crud.py
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
def delete_workflow(
    identifier: str,
    project: str | None = None,
    entity_id: str | None = None,
    delete_all_versions: bool = False,
    cascade: bool = True,
    **kwargs,
) -> dict:
    """
    Delete object from backend.

    Parameters
    ----------
    identifier : str
        Entity key (store://...) or entity name.
    project : str
        Project name.
    entity_id : str
        Entity ID.
    delete_all_versions : bool
        Delete all versions of the named entity. If True, use entity name instead of entity key as identifier.
    cascade : bool
        Cascade delete.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    dict
        Response from backend.

    Examples
    --------
    If delete_all_versions is False:
    >>> obj = delete_workflow("store://my-workflow-key")

    Otherwise:
    >>> obj = delete_workflow("workflow-name",
    >>>                       project="my-project",
    >>>                       delete_all_versions=True)
    """
    return delete_entity_api_ctx(
        identifier=identifier,
        entity_type=ENTITY_TYPE,
        project=project,
        entity_id=entity_id,
        delete_all_versions=delete_all_versions,
        cascade=cascade,
        **kwargs,
    )

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

Get object from backend.

Parameters:

Name Type Description Default
identifier str

Entity key (store://...) or entity name.

required
project str

Project name.

None
entity_id str

Entity ID.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
Workflow

Object instance.

Examples:

Using entity key:

>>> obj = get_workflow("store://my-workflow-key")

Using entity name:

>>> obj = get_workflow("my-workflow-name"
>>>                    project="my-project",
>>>                    entity_id="my-workflow-id")
Source code in digitalhub_core/entities/workflow/crud.py
 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
def get_workflow(
    identifier: str,
    project: str | None = None,
    entity_id: str | None = None,
    **kwargs,
) -> Workflow:
    """
    Get object from backend.

    Parameters
    ----------
    identifier : str
        Entity key (store://...) or entity name.
    project : str
        Project name.
    entity_id : str
        Entity ID.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    Workflow
        Object instance.

    Examples
    --------
    Using entity key:
    >>> obj = get_workflow("store://my-workflow-key")

    Using entity name:
    >>> obj = get_workflow("my-workflow-name"
    >>>                    project="my-project",
    >>>                    entity_id="my-workflow-id")
    """
    obj = read_entity_api_ctx(
        identifier,
        ENTITY_TYPE,
        project=project,
        entity_id=entity_id,
        **kwargs,
    )
    return workflow_from_dict(obj)

get_workflow_versions(identifier, project=None, **kwargs)

Get object versions from backend.

Parameters:

Name Type Description Default
identifier str

Entity key (store://...) or entity name.

required
project str

Project name.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[Workflow]

List of object instances.

Examples:

Using entity key:

>>> obj = get_workflow_versions("store://my-workflow-key")

Using entity name:

>>> obj = get_workflow_versions("my-workflow-name"
>>>                             project="my-project")
Source code in digitalhub_core/entities/workflow/crud.py
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
def get_workflow_versions(
    identifier: str,
    project: str | None = None,
    **kwargs,
) -> list[Workflow]:
    """
    Get object versions from backend.

    Parameters
    ----------
    identifier : str
        Entity key (store://...) or entity name.
    project : str
        Project name.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    list[Workflow]
        List of object instances.

    Examples
    --------
    Using entity key:
    >>> obj = get_workflow_versions("store://my-workflow-key")

    Using entity name:
    >>> obj = get_workflow_versions("my-workflow-name"
    >>>                             project="my-project")
    """
    obj = read_entity_api_ctx_versions(
        identifier,
        entity_type=ENTITY_TYPE,
        project=project,
        **kwargs,
    )
    return [workflow_from_dict(o) for o in obj]

import_workflow(file)

Import object from a YAML file.

Parameters:

Name Type Description Default
file str

Path to YAML file.

required

Returns:

Type Description
Workflow

Object instance.

Examples:

>>> obj = import_workflow("my-workflow.yaml")
Source code in digitalhub_core/entities/workflow/crud.py
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 import_workflow(file: str) -> Workflow:
    """
    Import object from a YAML file.

    Parameters
    ----------
    file : str
        Path to YAML file.

    Returns
    -------
    Workflow
        Object instance.

    Examples
    --------
    >>> obj = import_workflow("my-workflow.yaml")
    """
    obj: dict = read_yaml(file)
    if isinstance(obj, list):
        wf_dict = obj[0]
        task_dicts = obj[1:]
    else:
        wf_dict = obj
        task_dicts = []

    check_context(obj.get("project"))
    workflow = workflow_from_dict(wf_dict)
    workflow.import_tasks(task_dicts)
    return workflow

list_workflows(project, **kwargs)

List all latest version objects from backend.

Parameters:

Name Type Description Default
project str

Project name.

required
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[Workflow]

List of object instances.

Examples:

>>> objs = list_workflows(project="my-project")
Source code in digitalhub_core/entities/workflow/crud.py
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
def list_workflows(project: str, **kwargs) -> list[Workflow]:
    """
    List all latest version objects from backend.

    Parameters
    ----------
    project : str
        Project name.
    **kwargs : dict
        Parameters to pass to the API call.

    Returns
    -------
    list[Workflow]
        List of object instances.

    Examples
    --------
    >>> objs = list_workflows(project="my-project")
    """
    objs = list_entity_api_ctx(
        project=project,
        entity_type=ENTITY_TYPE,
        **kwargs,
    )
    return [workflow_from_dict(obj) for obj in objs]

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

Create a new object.

Parameters:

Name Type Description Default
project str

Project name.

required
name str

Object name.

required
uuid str

ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).

None
description str

Description of the object (human readable).

None
labels list[str]

List of labels.

None
embedded bool

Flag to determine if object spec must be embedded in project spec.

True
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Workflow

Object instance.

Examples:

>>> obj = new_function(project="my-project",
>>>                    name="my-function",
>>>                    kind="kfp",
>>>                    code_src="pipeline.py",
>>>                    handler="pipeline-handler")
Source code in digitalhub_core/entities/workflow/crud.py
23
24
25
26
27
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
def new_workflow(
    project: str,
    name: str,
    kind: str,
    uuid: str | None = None,
    description: str | None = None,
    labels: list[str] | None = None,
    embedded: bool = True,
    **kwargs,
) -> Workflow:
    """
    Create a new object.

    Parameters
    ----------
    project : str
        Project name.
    name : str
        Object name.
    uuid : str
        ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
    description : str
        Description of the object (human readable).
    labels : list[str]
        List of labels.
    embedded : bool
        Flag to determine if object spec must be embedded in project spec.
    **kwargs : dict
        Spec keyword arguments.

    Returns
    -------
    Workflow
        Object instance.

    Examples
    --------
    >>> obj = new_function(project="my-project",
    >>>                    name="my-function",
    >>>                    kind="kfp",
    >>>                    code_src="pipeline.py",
    >>>                    handler="pipeline-handler")
    """
    check_context(project)
    obj = workflow_from_parameters(
        project=project,
        name=name,
        kind=kind,
        uuid=uuid,
        description=description,
        labels=labels,
        embedded=embedded,
        **kwargs,
    )
    obj.save()
    return obj

update_workflow(entity)

Update object. Note that object spec are immutable.

Parameters:

Name Type Description Default
entity Workflow

Object to update.

required

Returns:

Type Description
Workflow

Entity updated.

Examples:

>>> obj = update_workflow(obj)
Source code in digitalhub_core/entities/workflow/crud.py
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
def update_workflow(entity: Workflow) -> Workflow:
    """
    Update object. Note that object spec are immutable.

    Parameters
    ----------
    entity : Workflow
        Object to update.

    Returns
    -------
    Workflow
        Entity updated.

    Examples
    --------
    >>> obj = update_workflow(obj)
    """
    return entity.save(update=True)