Fetch metadata within steps

Accessing meta information in real-time within your pipeline.

Using the StepContext

To find information about the pipeline or step that is currently running, you can use the zenml.get_step_context() function to access the StepContext of your step:

from zenml import step, get_step_context


@step
def my_step():
    step_context = get_step_context()
    pipeline_name = step_context.pipeline.name
    run_name = step_context.pipeline_run.name
    step_name = step_context.step_run.name

Furthermore, you can also use the StepContext to find out where the outputs of your current step will be stored and which Materializer class will be used to save them:

from zenml import step, get_step_context


@step
def my_step():
    step_context = get_step_context()
    # Get the URI where the output will be saved.
    uri = step_context.get_output_artifact_uri()

    # Get the materializer that will be used to save the output.
    materializer = step_context.get_output_materializer() 

See the SDK Docs for more information on which attributes and methods the StepContext provides.

ZenML Scarf

Last updated