artifact_version(name_id_or_prefix="iris_dataset")artifact.download_files("path/to/save.zip")

Take note that the path must have the .zip extension, as the artifact data will be saved as a zip file. Make sure to handle any exceptions that may arise from this operation.

Managing artifacts not produced by ZenML pipelines

Sometimes, artifacts can be produced completely outside of ZenML. A good example of this is the predictions produced by a deployed model.

# A model is deployed, running in a FastAPI container

# Let's use the ZenML client to fetch the latest model and make predictions

from zenml.client import Client

from zenml import save_artifact

# Fetch the model from a registry or a previous pipeline

model = ...

# Let's make a prediction

prediction = model.predict([[1, 1, 1, 1]])

# We now store this prediction in ZenML as an artifact

# This will create a new artifact version

save_artifact(prediction, name="iris_predictions")

You can also load any artifact stored within ZenML using the load_artifact method:

# Loads the latest version

load_artifact("iris_predictions")

load_artifact is simply short-hand for the following Client call:

from zenml.client import Client

client = Client()

client.get_artifact("iris_predictions").load()

Even if an artifact is created externally, it can be treated like any other artifact produced by ZenML steps - with all the functionalities described above!

It is also possible to use these functions inside your ZenML steps. However, it is usually cleaner to return the artifacts as outputs of your step to save them, or to use External Artifacts to load them instead.

Logging metadata for an artifact

One of the most useful ways of interacting with artifacts in ZenML is the ability to associate metadata with them. As mentioned before, artifact metadata is an arbitrary dictionary of key-value pairs that are useful for understanding the nature of the data.