Artifacts
This guide explains how to add artifacts to an MLOps entity, such as a project, dataset, experiment, or deployment, as well as how to retrieve, update, delete, or convert artifacts to a string or dictionary.
Prerequisitesβ
Before you begin,
- Connect to H2O MLOps. For instructions, see Connect to H2O MLOps.
- Create an MLOps entity and assign it to a variable named
entity
.- To create a project entity, see Create a project.
- To create an experiment entity, see Create an experiment.
Add an artifactβ
Use the add()
method to upload an artifact to an entity.
artifact = entity.artifacts.add(
data="/path/to/docx_artifact.docx",
mime_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
)
If you link a H2O Driverless AI (DAI) experiment to a project directly from a DAI instance, all its artifacts are added to the experiment automatically.
View artifactsβ
List artifactsβ
Use the list()
method to view all artifacts linked to an entity.
Input:
entity.artifacts.list()
Output:
| name | mime_type | uid
---+--------------------+---------------------------+--------------------------------------
0 | docx_artifact.docx | application/vnd.openxmlfo | 92e4ea49-fdcd-436b-9293-dcd0e8fdae18
Filter artifactsβ
Use the artifacts.list()
method with key-value arguments to filter the artifacts.
Input:
entity.artifacts.list(name="docx_artifact.docx")
This returns a list of matching artifacts as a table.
Output:
| name | mime_type | uid
---+--------------------+---------------------------+--------------------------------------
0 | docx_artifact.docx | application/vnd.openxmlfo | 92e4ea49-fdcd-436b-9293-dcd0e8fdae18
Retrieve an artifactβ
Use the get()
method to retrieve a specific artifact by its unique ID.
Input:
artifact = entity.artifacts.get(uid="92e4ea49-fdcd-436b-9293-dcd0e8fdae18")
artifact
You can retrieve a specific artifact from the list returned by artifacts.list()
using indexing.
For example, artifact = entity.artifacts.list(key=value)[index]
. The key
and value
arguments are optional.
Output:
<class 'h2o_mlops._artifacts.MLOpsArtifact(
uid='92e4ea49-fdcd-436b-9293-dcd0e8fdae18',
parent_entity_uid='777b3d15-36ba-4a96-b687-47e3d6687d4d',
name='docx_artifact.docx',
state='AVAILABLE',
mime_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document',
size=0,
md5_digest='1B2M2Y8AsgTpgAmY7PhCfg==',
created_time=datetime.datetime(2025, 6, 11, 17, 31, 12, 850635, tzinfo=tzutc()),
uploaded_time=datetime.datetime(2025, 6, 11, 17, 31, 16, 26743, tzinfo=tzutc()),
last_modified_time=datetime.datetime(2025, 6, 11, 17, 31, 16, 27248, tzinfo=tzutc())
)'>
Artifact propertiesβ
An artifact has the following main properties:
uid
: Unique ID of the artifactparent_entity_uid
: ID of the parent project, dataset, etc.name
: Name of the artifactstate
: Artifact statemime_type
: File type of the artifactsize
: File size in bytesmd5_digest
: MD5 hash of the artifactcreated_time
: Timestamp when the artifact was createduploaded_time
: Timestamp when the artifact was uploadedlast_modified_time
: Last time the artifact was updatedmodel_info
: Model-specific metadata, if applicable
Download an artifactβ
To download an artifact:
Input:
artifact.download()
Output:
'docx_artifact.docx'
The download()
method supports the following optional parameters:
directory
: Target folder (default: current working directory)file_name
: Output filename (default: artifactβs name)overwrite
: Whether to overwrite the file if it exists (default:False
)buffer
: Store the file in memory usingio.BytesIO
instead of writing to disk
-
If you don't specify any options, the artifact downloads to the current working directory using its name.
-
If the artifact name does not include a file extension, you must pass the
file_name
argument with the appropriate extension. You can use the artifact's MIME type (mime_type
) to determine the correct file extension.Common MIME types and corresponding file extensions:
MIME type File extension application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx
application/json .json
text/plain .txt
application/zip .zip
application/pdf .pdf
image/png .png
Convert artifactsβ
Artifacts can be converted to string or dictionary format, depending on their type:
- A JSON artifact can be converted to a string or a dictionary.
- A text artifact can only be converted to a string.
- Other artifact types cannot be converted, except zip artifacts of type
vLLM Configuration
(vllm/config
).
Convert JSON artifactsβ
To convert JSON artifacts to a string and a dictionary, follow these steps:
-
Add the JSON file to the specified entity as an artifact.
json_artifact = entity.artifacts.add(
data="/path/to/json_artifact.json",
mime_type="application/json",
) -
Convert the JSON artifact to a string:
Input:
json_artifact.to_string()
Output:
'{\n "key": "value"\n}\n'
-
Convert a JSON artifact to a dictionary:
Input:
json_artifact.to_dict()
Output:
{'key': 'value'}
Convert text artifactsβ
To convert text artifacts to a string, follow these steps:
-
Add the text file to the specified entity as an artifact.
text_artifact = entity.artifacts.add(
data="/path/to/txt_artifact.txt",
mime_type="text/plain",
) -
Convert the text artifact to a string:
Input:
text_artifact.to_string()
Output:
"It's a text file.\n"
Update an artifactβ
You can update only the name
and parent_entity
fields of an artifact.
Make sure to retrieve the artifact before updating it. See Retrieve an artifact.
Input:
artifact.update(name="my-docx-artifact")
artifact
Output:
<class 'h2o_mlops._artifacts.MLOpsArtifact(
uid='92e4ea49-fdcd-436b-9293-dcd0e8fdae18',
parent_entity_uid='777b3d15-36ba-4a96-b687-47e3d6687d4d',
name='my-docx-artifact',
state='AVAILABLE',
mime_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document',
size=0,
md5_digest='1B2M2Y8AsgTpgAmY7PhCfg==',
created_time=datetime.datetime(2025, 6, 11, 17, 31, 12, 850635, tzinfo=tzutc()),
uploaded_time=datetime.datetime(2025, 6, 11, 17, 31, 16, 26743, tzinfo=tzutc()),
last_modified_time=datetime.datetime(2025, 6, 11, 17, 31, 36, 773648, tzinfo=tzutc())
)'>
Delete an artifactβ
This section describes how to delete an artifact.
Use the delete()
method to remove the artifact from the entity:
Input:
artifact.delete()
entity.artifacts.list()
In this example, artifact.delete()
deletes the docx_artifact.docx
artifact assigned to the artifact variable earlier in the Add an artifact section and retrieved in the Retrieve an artifact section.
The list()
output confirms that the artifact has been successfully removed.
Output:
| name | mime_type | uid
---+--------------------+------------------+--------------------------------------
0 | txt_artifact.txt | text/plain | 04eaf9e2-f6cf-4140-9686-b31290f7fd17
1 | json_artifact.json | application/json | 5d442fc2-d0ae-42eb-8050-42255fa8c10a
After deletion, the docx_artifact.docx
artifact no longer appears in the list of artifacts for the entity.
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai