CRUD
The CRUD methods are used to create, read, update and delete artifacts. 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 artifacts 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.
Example:
import digitalhub as dh
project = dh.get_or_create_project("my-project")
# Use CRUD method on project
artifact = project.new_artifact(name="my-artifact",
kind="artifact",
path="path-to-some-file")
# Use CRUD method from SDK
artifact = dh.new_artifact(project="my-project",
name="my-artifact",
kind="artifact",
path="path-to-some-file")
An artifact entity can be managed with the following methods.
Create:
Read:
Update:
Delete:
Create
You can create an artifact with the new_artifact() or with log_artifact() method.
The kwargs parameters are determined by the kind of the object, and are described in the kinds section.
The kwargs parameters are the same for both new and log methods.
New
This function create a new entity and saves it into the backend.
new_artifact
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
Project name. |
required |
name
|
str
|
Object name. |
required |
kind
|
str
|
Kind the object. |
required |
uuid
|
str
|
ID of the object. |
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. |
False
|
path
|
str
|
Object path on local file system or remote storage. It is also the destination path of upload() method. |
None
|
**kwargs
|
dict
|
Spec keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Artifact
|
Object instance. |
Examples:
Log
This function create a new entity into the backend and also upload a local file into an artifact store (eg. S3).
log_artifact
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
Project name. |
required |
name
|
str
|
Object name. |
required |
kind
|
str
|
Kind the object. |
required |
source
|
SourcesOrListOfSources
|
Artifact location on local path. |
required |
path
|
str
|
Destination path of the artifact. If not provided, it's generated. |
None
|
**kwargs
|
dict
|
New artifact spec parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
Artifact
|
Object instance. |
Examples:
Read
To read artifacts you can use the get_artifact(), get_artifact_versions(), list_artifacts() or import_artifact() functions.
Get
This function searches for a single artifact into the backend.
If you want to collect an artifact from the backend using get_artifact(), you have two options:
- The first one is to use the
keyparameter which has the patternstore://<project-name>/<entity-type>/<entity-kind>/<entity-name>:<entity-id>. - The second one is to use the entity name as
identifier, the project name asprojectand the entity id asentity_idparameters. If you do not specify the entity id, you will get the latest version.
get_artifact
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 |
|---|---|
Artifact
|
Object instance. |
Examples:
Using entity key:
Using entity name:
Get versions
This function returns all the versions of an artifact from the backend.
get_artifact_versions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
Entity key (store://...) or entity name. |
required |
project
|
str
|
Project name. |
None
|
Returns:
| Type | Description |
|---|---|
list[Artifact]
|
List of object instances. |
Examples:
Using entity key:
Using entity name:
List
This function returns all the latest artifacts from the backend related to a project.
list_artifacts
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
|
versions
|
str
|
Object version, default is latest. |
None
|
Returns:
| Type | Description |
|---|---|
list[Artifact]
|
List of object instances. |
Examples:
Import
This function load the artifact from a local yaml file descriptor.
import_artifact
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 |
|---|---|
Artifact
|
Object instance. |
Examples:
Update
To update an artifact you can use the update_artifact() method.
Delete
To delete an artifact you can use the delete_artifact() method.
delete_artifact
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
|
Returns:
| Type | Description |
|---|---|
dict
|
Response from backend. |
Examples:
If delete_all_versions is False:
Otherwise: