Artifact Store and the local filesystem or memory.When calling the Artifact Store API, you should always use URIs that are relative to the Artifact Store root path, otherwise, you risk using an unsupported protocol or storing objects outside the store. You can use the Repository singleton to retrieve the root path of the active Artifact Store and then use it as a base path for artifact URIs, e.g.:

import os

from zenml.client import Client

from zenml.io import fileio

root_path = Client().active_stack.artifact_store.path

artifact_contents = "example artifact"

artifact_path = os.path.join(root_path, "artifacts", "examples")

artifact_uri = os.path.join(artifact_path, "test.txt")

fileio.makedirs(artifact_path)

with fileio.open(artifact_uri, "w") as f:

f.write(artifact_contents)

When using the Artifact Store API to write custom Materializers, the base artifact URI path is already provided. See the documentation on Materializers for an example.

The following are some code examples showing how to use the Artifact Store API for various operations:

creating folders, writing and reading data directly to/from an artifact store object

import os

from zenml.utils import io_utils

from zenml.io import fileio

from zenml.client import Client

root_path = Client().active_stack.artifact_store.path

artifact_contents = "example artifact"

artifact_path = os.path.join(root_path, "artifacts", "examples")

artifact_uri = os.path.join(artifact_path, "test.txt")

fileio.makedirs(artifact_path)

io_utils.write_file_contents_as_string(artifact_uri, artifact_contents)

import os

from zenml.utils import io_utils

from zenml.client import Client

root_path = Client().active_stack.artifact_store.path

artifact_path = os.path.join(root_path, "artifacts", "examples")

artifact_uri = os.path.join(artifact_path, "test.txt")

artifact_contents = io_utils.read_file_contents_as_string(artifact_uri)