CRUD
The CRUD methods are used to create, read, update and delete models. 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 models 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
model = project.new_model(name="my-model",
kind="model",
path="path-to-some-model")
# Use CRUD method from SDK
model = dh.new_model(project="my-project",
name="my-model",
kind="model",
path="path-to-some-model")
A model
entity can be managed with the following methods.
Create:
Read:
Update:
Delete:
Create
You can create a model with the new_model()
or with log_model()
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_model
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 |
---|---|
Model
|
Object instance. |
Examples:
Log
This function create a new entity into the backend and also upload a local file into a model store (eg. S3).
log_model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project
|
str
|
Project name. |
required |
name
|
str
|
Object name. |
required |
kind
|
str
|
Kind the object. |
required |
source
|
str
|
Model location on local path. |
required |
path
|
str
|
Destination path of the model. If not provided, it's generated. |
None
|
**kwargs
|
dict
|
New model spec parameters. |
{}
|
Returns:
Type | Description |
---|---|
Model
|
Object instance. |
Examples:
Read
To read models you can use the get_model()
, get_model_versions()
, list_models()
or import_model()
functions.
Get
This function searches for a single model into the backend.
If you want to collect a model from the backend using get_model()
, you have two options:
- The first one is to use the
key
parameter 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 asproject
and the entity id asentity_id
parameters. If you do not specify the entity id, you will get the latest version.
get_model
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 |
---|---|
Model
|
Object instance. |
Examples:
Using entity key:
Using entity name:
Get versions
This function returns all the versions of a model from the backend.
get_model_versions
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[Model]
|
List of object instances. |
Examples:
Using entity key:
Using entity name:
List
This function returns all the latest models from the backend related to a project.
Import
This function load the model from a local yaml file descriptor.
Update
To update a model you can use the update_model()
method.
Delete
To delete a model you can use the delete_model()
method.
delete_model
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
|
**kwargs
|
dict
|
Parameters to pass to the API call. |
{}
|
Returns:
Type | Description |
---|---|
dict
|
Response from backend. |
Examples:
If delete_all_versions is False:
Otherwise: