@asset syntax in Apache Airflow®
@asset syntax in Apache Airflow®
@asset syntax in Apache Airflow®
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:
@asset to create a Dag with one task that updates an asset.@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.
To get the most out of this guide, you should have an existing knowledge of:
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.
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:

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.