How to use assets to track workflow outputs
Assets in Prefect represent important outputs (such as data) that are produced by your tasks and flows. Assets can reference virtually any output such as files, dataframes, tables, dashboards, or ML models. By using the @materialize
decorator, you can track when your workflows create, update, or reference these objects.
Basic asset materialization
Use the @materialize
decorator to mark functions that create or update assets. This decorator wraps your function similar to @task
but specifically tracks asset creation:
Asset keys must be valid URIs that uniquely identify your workflow outputs. Assets are automatically grouped by type (specified by the URI prefix) and can be nested based on the URI path structure. For example, s3://
assets are grouped separately from postgres://
assets, and nested paths like s3://bucket/team-a/data.csv
and s3://bucket/team-b/data.csv
create hierarchical organization.
@materialize
wraps @task
: the @materialize
decorator accepts all keyword arguments and configuration that the @task
decorator accepts and can be used as a drop-in replacement.
Asset dependencies
Inferred from task graphs
Prefect automatically infers asset dependencies from your task graph. When materialized assets flow through your workflow, downstream materializations inherit these dependencies:
Running this flow produces the following asset graph:
External and cross-flow asset dependencies
Use asset_deps
to reference assets that are external to your current workflow. This creates dependencies on assets that may be materialized by other flows, external systems, or manual processes:
Running this flow produces the following asset graph:
This approach allows you to model your complete data ecosystem, tracking dependencies even when some assets are managed outside your current workflow or outside Prefect entirely.
Multiple asset materialization
Materialize multiple related assets in a single function when they share the same upstream dependencies: