Subchapter 2.5
references/assets/INDEX.mdMarkdown3 KBView on GitHub
@dg.asset — simple one-to-one transformationdeps= dependency — asset depends on external or non-Python asset, data dependency only@multi_asset — single operation produces multiple related assets@graph_asset — multiple op steps needed to produce one asset@graph_multi_asset — complex pipeline producing multiple assets from composed opsBasic @dg.asset: Function name becomes the asset key. Docstring becomes the description in the UI. Return type annotation is optional but recommended.
Asset groups: Use group_name= on the decorator to organize assets visually in the UI. Common groupings: by data layer (raw, staging, analytics), by domain (sales, marketing), or by source (postgres, api).
Key prefixes: Use key_prefix=["warehouse", "raw"] to namespace asset keys hierarchically (e.g. warehouse/raw/orders). Useful for multi-tenant or layered architectures.
Configuration: Subclass dg.Config with typed fields, then add as a parameter to your asset function. Fields become configurable at launch time.
Execution context: Add context: dg.AssetExecutionContext as a parameter to access context.log, context.asset_key, context.partition_key (if partitioned), and context.run_id.
Return types: Assets can return data directly (passed to downstream via IOManager) or dg.MaterializeResult (for metadata, or dg.MaterializeResult[T] for data + metadata). MaterializeResult[T] is preferred over dg.Output[T] in greenfield code.
load_customers — use nouns describing the output: customers-> dict, -> Nonedescription=MaterializeResult — return metadata for observability