Write Airflow tasks as Python functions with TaskFlow
Answer: TaskFlow, added in version 2.0, uses XCom to pass variables to each task. A decorated function yields an XComArg, and a returned dict can unroll into several XCom values.
Functions as tasks
TaskFlow was added in version 2.0. As mentioned, TaskFlow uses XCom to pass variables to each task. A @task decorated function returns an XComArg that downstream tasks can use as inputs.
task_decorator_factory returns an instance of the decorator, instead of just a plain wrapped function. The __call__ method returns an XComArg, and expand and expand_kwargs also return an XComArg.
| TaskFlow | XCom | |---|---| | added in version 2.0 | pass variables to each task | | XComArg | return value of a decorated function | | multiple_outputs | unroll a return value |
DecoratedOperator
DecoratedOperator wraps a Python callable and captures args and kwargs when called for execution. When multiple_outputs is True, the decorated function's return value is unrolled to multiple XCom values. A dict unrolls so that its keys become the XCom keys. When the flag is False, the default, at most one XCom value is pushed.
See also
Claims
- id: C1 claim: TaskFlow uses XCom to pass variables to each task. source: S1 evidence: "As mentioned TaskFlow uses XCom to pass variables to each task."
- id: C2 claim: When multiple_outputs is true, a returned dict unrolls into XCom values keyed by the dict. source: S2 evidence: "Dict will unroll to XCom values with its keys as XCom keys."
- id: C3 claim: When multiple_outputs is false, at most one XCom value is pushed. source: S2 evidence: "If set to False (default), only at most one XCom value is pushed."
Sources
- [S1] TaskFlow. Apache Airflow docs. https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/taskflow.html . License: Apache-2.0. Accessed 2026-11-20.
- [S2] decorator.py (DecoratedOperator). Apache Airflow source. https://raw.githubusercontent.com/apache/airflow/main/task-sdk/src/airflow/sdk/bases/decorator.py . License: Apache-2.0. Accessed 2026-11-20.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Apache Airflow docs, TaskFlow; Apache Airflow source, decorator.py (DecoratedOperator). Apache-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Apache Airflow docs, TaskFlow; Apache Airflow source, decorator.py (DecoratedOperator). Apache-2.0.
Cite this
iinventedlight. 2026. "Write Airflow tasks as Python functions with TaskFlow." iinventedlight Library, iil:note:jmctbtd0, version of 2026-11-20. https://iinventedlight.com/library/notes/airflow-taskflow/. License: CC-BY-4.0.
@misc{iil_note_jmctbtd0,
author = {{iinventedlight}},
title = {{Write Airflow tasks as Python functions with TaskFlow}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-20},
url = {https://iinventedlight.com/library/notes/airflow-taskflow/},
note = {Permanent ID iil:note:jmctbtd0. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- airflow-taskflow.table.json (table; CC-BY-4.0)
- airflow-taskflow.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/airflow-taskflow.md.