Skip to main content

Documentation Index

Fetch the complete documentation index at: https://astronomer-preview.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

The @asset decorator is a shorthand to create one Dag with one task that updates an asset. This decorator is used in the asset-oriented approach to writing Dags which constitutes a mindset shift to put the data asset front and center. Whether you use the asset-oriented or task-oriented approach to writing Dags is a matter of preference. Dags created using the asset-oriented approach are shown like any other Dag in the Airflow UI. In this guide, you’ll learn:
  • How to use @asset to create a Dag with one task that updates an asset.
  • How to use @asset.multi to create a Dag with one task that updates multiple assets.
If you are looking for instructions on how to use asset-based scheduling in Airflow with the Asset object, see Basic asset-based scheduling in Apache Airflow®, as well as Advanced asset-based scheduling.
The @asset decorator is an example of a Dag authoring paradigm (asset-oriented) that is different from the task-oriented approach. To learn more about different Dag authoring paradigms, check out the free Apache Airflow® orchestration paradigms ebook.

Assumed knowledge

To get the most out of this guide, you should have an existing knowledge of:

Using @asset

The following code snippet defines a Dag with the Dag ID my_asset that runs on a @daily schedule. It contains one task with the task ID my_asset that, upon successful completion updates an asset with the name my_asset.
from airflow.sdk import asset 

@asset(schedule="@daily")
def my_asset():
    # your task logic here
    pass
You can schedule assets based on other assets to create data-centric pipelines. Since each @asset decorator creates one Dag, data needs to be passed between tasks using cross-Dag XComs. The following shows the same simple ETL pipeline accomplished using the asset-oriented and the task-oriented approach. The code above creates three Dags that depend on each other, each containing one task that updates one asset: DAGs view showing 3 DAGs.

@asset.multi

To update several assets from the same Dag written with the asset-oriented approach, you can use @asset.multi. The code example below will create one Dag with the Dag ID my_multi_asset that contains one task called my_multi_asset that, upon successful completion, updates two assets with the names asset_a and asset_b.
from airflow.sdk import Asset, asset

@asset.multi(schedule="@daily", outlets=[Asset("asset_a"), Asset("asset_b")])
def my_multi_asset():
    pass