Skip to content

CRUD

The CRUD methods are used to create, read, update and delete runs. There are two ways to use them. The first is through the SDK and the second is through the Project object. The syntax is the same for all CRUD methods. If you want to manage runs from the project, you can use the Project object and avoid to specify the project parameter. In this last case, you need to specify every parameter as keyword argument. In any case, you need to first import the SDK and instantiate a Project object that will be the context in which you can manage entities.

Example:

import digitalhub as dh

project = dh.get_or_create_project("my-project")

# Use CRUD method on project

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

# 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
**kwargs dict

Parameters to pass to the API call.

{}

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
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[Run]

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 YAML file.

required

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 ID.

required
project str

Project name.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
dict

Response from backend.

Examples:

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