Skip to content

CRUD

The CRUD methods are used to create, read, update and delete runs. The syntax is the same for all CRUD methods.

Example:

import digitalhub as dh

# Use CRUD method from SDK

run = dh.new_run(project="my-project",
                 kind="python+run",
                 task="task-string")

A run entity can be managed with the following methods.

Create:

Read:

Update:

Delete:

Create

You can create a run with the new_run(). The kwargs parameters are determined by the kind of the object, and are described in the kinds section.

New

This run create a new entity and saves it into the backend.

new_run

Parameters:

Name Type Description Default
project str

Project name.

required
kind str

Kind the object.

required
uuid str

ID of the object.

None
labels list[str]

List of labels.

None
task str

Name of the task associated with the run.

None
local_execution bool

Flag to determine if object has local execution.

False
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Run

Object instance.

Examples:

>>> obj = new_run(project="my-project",
>>>               kind="python+run",
>>>               task="task-string")

Read

To read runs you can use the get_run(), list_runs() or import_run() runs.

Get

This run searches for a single run into the backend. If you want to collect a run from the backend using get_run(), you have two options:

  • The first one is to use the key parameter which has the pattern store://<project-name>/<entity-type>/<entity-kind>/<entity-id>.
  • The second one is to use the entity id as identifier, the project name as project.
get_run

Parameters:

Name Type Description Default
identifier str

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

required
project str

Project name.

None

Returns:

Type Description
Run

Object instance.

Examples:

Using entity key:

>>> obj = get_run("store://my-run-key")

Using entity ID:

>>> obj = get_run("my-run-id"
>>>               project="my-project")

List

This run returns all the latest runs from the backend related to a project.

list_runs

Parameters:

Name Type Description Default
project str

Project name.

required
q str

Query string to filter objects.

None
name str

Object name.

None
kind str

Kind of the object.

None
user str

User that created the object.

None
state str

Object state.

None
created str

Creation date filter.

None
updated str

Update date filter.

None
function str

Function key filter.

None
workflow str

Workflow key filter.

None
task str

Task string filter.

None
action str

Action name filter.

None

Returns:

Type Description
list[Model]

List of object instances.

Examples:

>>> objs = list_runs(project="my-project")

Import

This run load the run from a local yaml file descriptor.

import_run

Parameters:

Name Type Description Default
file str

Path to the YAML file.

None
key str

Entity key (store://...).

None
reset_id bool

Flag to determine if the ID of executable entities should be reset.

False
context str

Project name to use for context resolution.

None

Returns:

Type Description
Run

Object instance.

Update

To update a run you can use the update_run() method.

update_run

Parameters:

Name Type Description Default
entity Run

Object to update.

required

Returns:

Type Description
Run

Entity updated.

Examples:

>>> obj = update_run(obj)

Delete

To delete a run you can use the delete_run() method.

delete_run

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

Returns:

Type Description
dict

Response from backend.

Examples:

>>> obj = delete_run("store://my-run-key")
>>> obj = delete_run(
...     "my-run-id",
...     project="my-project",
... )