Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:PrefectHQ Prefect Materialize Decorator

From Leeroopedia
Revision as of 16:22, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/PrefectHQ_Prefect_Materialize_Decorator.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Metadata
Source Repo: Prefect
Domains Data_Engineering, Orchestration
Last Updated 2026-02-09 00:00 GMT

Overview

Concrete decorator for creating tracked, versioned data asset materializations provided by the Prefect library.

Description

The @materialize decorator from prefect.assets wraps a function to track its output as a named data asset. It takes an Asset instance as argument and automatically:

  • Tracks the function's return value as that asset
  • Infers dependencies from function parameters matching upstream asset names
  • Enables caching and versioning
  • Records lineage in the Prefect UI

Code Reference

  • Repository: https://github.com/PrefectHQ/prefect
  • File: src/prefect/assets/materialize.py (L17) for the decorator, examples/atproto_dashboard_with_prefect_assets.py (L73-152) for usage
  • Signature:
def materialize(asset: Asset) -> Callable:
    """Decorator that marks a function as materializing a specific asset.

    Args:
        asset: The Asset instance this function materializes.
    """
  • Import: from prefect.assets import Asset, materialize

I/O Contract

  • Inputs: asset (Asset, required -- the asset this function produces)
  • The decorated function's parameters define upstream dependencies
  • Outputs: The decorated function's return value, tracked as the specified asset

Usage Example

from prefect.assets import Asset, materialize
from prefect import flow

raw_data_asset = Asset(key="pipeline://raw_data")
processed_data_asset = Asset(key="pipeline://processed_data")

@materialize(raw_data_asset)
def fetch_raw_data() -> dict:
    return {"items": ["item1", "item2"], "fetched_at": "2026-01-01", "count": 2}

@materialize(processed_data_asset)
def process_data(raw_data: dict) -> dict:
    # Prefect infers dependency on raw_data_asset from parameter name
    return {"items": [item.upper() for item in raw_data["items"]],
            "processed_at": "2026-01-01"}

@flow(name="asset-pipeline-demo", log_prints=True)
def run_pipeline():
    raw = fetch_raw_data()
    processed = process_data(raw)
    return processed

Related Pages

Principle:PrefectHQ_Prefect_Asset_Materialization

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment