Skip to content

Model object

The Model object comes with three sets of methods: CRUD methods, I/O methods and kind specific methods.

CRUD methods

Crud methods are used to interact with the entity object in the backend or locally.

  • save(): Save or update the entity into the backend.
  • export(): Export the entity locally as yaml file.
  • refresh(): Refresh (read) the entity from the backend.

save

Save entity into backend.

Parameters:

Name Type Description Default
update bool

Flag to indicate update.

False

Returns:

Type Description
MaterialEntity

Entity saved.

export

Export object as a YAML file.

Parameters:

Name Type Description Default
filename str

Name of the export YAML file. If not specified, the default value is used.

None

Returns:

Type Description
None

refresh

Refresh object from backend.

Returns:

Type Description
ContextEntity

Entity refreshed.

I/O methods

I/O methods are used to handle objects as files.

  • as_file(): Dowloads the model into a local temporary destination
  • download(): Downloads the model into a specified path
  • upload(): Uploads the model to model spec path

as_file

Get object as file(s). It downloads the object from storage in a temporary folder and returns the list of downloaded files paths.

Returns:

Type Description
list[str]

List of file paths.

download

This function downloads one or more file from storage on local machine. It looks inside the object's status for the file(s) path under files attribute. If it does not find it, it will try to download what it can from spec.path. The files are downloaded into a destination folder. If the destination is not specified, it will set by default under the context path as '/', e.g. './dataitem'. The overwrite flag allows to overwrite existing file(s) in the destination folder.

Parameters:

Name Type Description Default
destination str

Destination path as filename or directory.

None
overwrite bool

Specify if overwrite existing file(s). If file(s) already exist and overwrite is False, it will raise an error.

False

Returns:

Type Description
str

Downloaded path.

Examples:

Download a single file:

>>> entity.status.files[0]
{
    "path ": "data.csv",
    "name ": "data.csv",
    "content_type ": "text/csv;charset=utf-8 "
}
>>> path = entity.download()
>>> print(path)
dataitem/data.csv

upload

Upload object from given local path to spec path destination. Source must be a local path. If the path is a folder, destination path (object's spec path) must be a folder or a partition ending with '/' (s3).

Parameters:

Name Type Description Default
source str | list[str]

Local filepath, directory or list of filepaths.

required

Returns:

Type Description
None

Examples:

Upload a single file:

>>> entity.spec.path = 's3://bucket/data.csv'
>>> entity.upload('./data.csv')

Upload a folder:

>>> entity.spec.path = 's3://bucket/data/'
>>> entity.upload('./data')

Kind specific methods

Kind specific methods are used to express potential behaviors of different object kinds. See the kinds section for more information.