Skip to content

CRUD

The CRUD methods are used to create, read, update and delete projects.

Example:

import digitalhub as dh

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

A project entity can be managed with the following methods.

Create:

Read:

Read or create:

Update:

Delete:

For project configuration options, please refer to the Config section, and the Setup section.

Create

You can create a project with the new_project() or with log_project() method.

New

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

new_project

Parameters:

Name Type Description Default
name str

Object name.

required
description str

Description of the object (human readable).

None
labels list[str]

List of labels.

None
local bool

If True, use local backend, if False use DHCore backend. Default to False.

False
config dict

DHCore environment configuration.

None
context str

The context local folder of the project.

None
setup_kwargs dict

Setup keyword arguments passed to setup_project() function.

None
**kwargs dict

Keyword arguments.

{}

Returns:

Type Description
Project

Object instance.

Examples:

>>> obj = new_project("my-project")

Read

To read projects you can use the get_project(), import_project() or load_project().

Get

This function searches for a single project into the backend.

get_project

Parameters:

Name Type Description Default
name str

The Project name.

required
local bool

Flag to determine if backend is local.

False
config dict

DHCore environment configuration.

None
setup_kwargs dict

Setup keyword arguments passed to setup_project() function.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
Project

Object instance.

Examples:

>>> obj = get_project("my-project")

Import

This function load the project from a local yaml file descriptor.

import_project

Parameters:

Name Type Description Default
file str

Path to YAML file.

required
local bool

Flag to determine if backend is local.

False
config dict

DHCore environment configuration.

None
setup_kwargs dict

Setup keyword arguments passed to setup_project() function.

None

Returns:

Type Description
Project

Object instance.

Examples:

>>> obj = import_project("my-project.yaml")

Load

This function returns a projects from the backend or from a local file according to the parameter passed to the function. If the parameter is name, the function will try to load the project from the backend. If the parameter is file, the function will try to load the project from the local file.

load_project

Parameters:

Name Type Description Default
name str

Project name.

None
filename str

Path to YAML file.

None
local bool

Flag to determine if backend is local.

False
config dict

DHCore environment configuration.

None
setup_kwargs dict

Setup keyword arguments passed to setup_project() function.

None
**kwargs dict

Keyword arguments.

{}

Returns:

Type Description
Project

Object instance.

Examples:

If name is provided, load project from backend.

>>> obj = load_project(name="my-project")

If filename is provided, load project from file.

>>> obj = load_project(filename="my-project.yaml")

Read or create

You can read or create a project with the get_or_create_project() method.

get_or_create_project

Parameters:

Name Type Description Default
name str

Project name.

required
local bool

Flag to determine if backend is local.

False
config dict

DHCore environment configuration.

None
context str

Folder where the project will saves its context locally.

None
setup_kwargs dict

Setup keyword arguments passed to setup_project() function.

None
**kwargs dict

Keyword arguments.

{}

Returns:

Type Description
Project

Object instance.

Update

To update a project you can use the update_project() method.

update_project

Parameters:

Name Type Description Default
entity Project

Object to update.

required
local bool

Flag to determine if backend is local.

False
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
Project

The updated object.

Examples:

>>> obj = update_project(obj)

Delete

To delete a project you can use the delete_project() method.

delete_project

Parameters:

Name Type Description Default
name str

Project name.

required
cascade bool

Flag to determine if delete is cascading.

True
clean_context bool

Flag to determine if context will be deleted. If a context is deleted, all its objects are unreacheable.

True
local bool

Flag to determine if backend is local.

False
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
dict

Response from backend.

Examples:

>>> delete_project("my-project")