← All notes

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

Sources

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

Permanent ID: iil:note:jmctbtd0

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.},
}

Markdown

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.

All artifact files (JSON index)

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.