Use this file to discover all available pages before exploring further.
Artifacts are the data objects produced by pipeline steps. ZenML automatically tracks, versions, and stores all artifacts, making it easy to trace data lineage, reproduce results, and share outputs across pipeline runs.
The second argument in Annotated becomes the artifact name:
3
from typing import Annotated@stepdef train_model() -> Annotated[object, "trained_model"]: """Produces an artifact named 'trained_model'.""" model = {"weights": [1, 2, 3]} return model
4
Step 2: Configure Custom Names
5
Use ArtifactConfig for more control:
6
from zenml import step, ArtifactConfigfrom typing import Annotated@stepdef train_model() -> Annotated[ object, ArtifactConfig( name="production_model", version=42, tags=["production", "v2"] )]: """Produces a configured artifact.""" model = {"weights": [1, 2, 3]} return model
7
Step 3: Dynamic Naming with Placeholders
8
Create dynamic artifact names:
9
from zenml import step, ArtifactConfigfrom typing import Annotated@stepdef train_model() -> Annotated[ object, ArtifactConfig( name="model_{date}_{time}", )]: """Creates artifacts like 'model_20260309_143022'.""" model = {"weights": [1, 2, 3]} return model
10
With custom placeholders:
11
@step( substitutions={"model_version": "v2.1"})def train_model() -> Annotated[ object, ArtifactConfig( name="model_{model_version}_{date}", )]: """Creates artifacts like 'model_v2.1_20260309'.""" model = {"weights": [1, 2, 3]} return model
from zenml import step, ArtifactConfigfrom zenml.enums import ArtifactTypefrom typing import Annotated@stepdef train_model() -> Annotated[ object, ArtifactConfig( name="model", artifact_type=ArtifactType.MODEL # Semantic type )]: """Explicitly mark this as a MODEL artifact.""" return model@stepdef generate_report() -> Annotated[ str, ArtifactConfig( name="report", artifact_type=ArtifactType.DATA # Mark as DATA )]: """Generate a data report.""" return "Model evaluation report: ..."
from zenml.client import Clientclient = Client()# Load latest version of an artifact by nameartifact = client.get_artifact_version(name="trained_model")model = artifact.load()# Load specific versionartifact = client.get_artifact_version( name="trained_model", version="42")model = artifact.load()# Load by IDartifact = client.get_artifact_version( name_id_or_prefix="550e8400-e29b-41d4-a716-446655440000")model = artifact.load()
from zenml.client import Clientclient = Client()# Get a specific pipeline runrun = client.get_pipeline_run("my_pipeline_run_name")# Load artifact from a specific stepmodel = run.steps["train_model"].outputs["trained_model"].load()# Or get the output directly if there's only onemodel = run.steps["train_model"].output.load()
from zenml.client import Clientclient = Client()# List all versions of an artifactartifact_versions = client.list_artifact_versions( name="trained_model")for version in artifact_versions: print(f"Version {version.version}: {version.id}") print(f" Created: {version.created}") print(f" Tags: {version.tags}")
@stepdef promote_model_to_production(metrics: dict) -> None: """Promote model if it meets criteria.""" client = Client() if metrics["accuracy"] > 0.95: # Get the current model from this run context = get_step_context() current_run = context.pipeline_run model_artifact = current_run.steps["train_model"].output # Update tags to mark as production client.update_artifact_version( artifact_version_id=model_artifact.id, tags=["production", "promoted"] ) print(f"Model {model_artifact.id} promoted to production") else: print("Model did not meet promotion criteria")
Track where artifacts come from and where they’re used:
from zenml.client import Clientclient = Client()# Get an artifactartifact = client.get_artifact_version(name="trained_model")# Find which step produced itproducer_step = artifact.producer_step_runprint(f"Produced by: {producer_step.name}")print(f"In pipeline: {producer_step.pipeline_run.name}")# Find which steps consumed it (if any)# Navigate through pipeline runs to find consumers
Artifacts are stored in the artifact store configured in your stack:
# View current artifact storezenml stack describe# List available artifact storeszenml artifact-store list# Register a new artifact store (e.g., S3)zenml artifact-store register my_s3_store \ --flavor=s3 \ --path=s3://my-bucket/zenml-artifacts
from zenml.client import Clientclient = Client()# List all artifacts to find the right nameall_artifacts = client.list_artifact_versions()for artifact in all_artifacts: print(f"{artifact.name} v{artifact.version}")