---
source: https://iinventedlight.com/library/notes/airflow-taskflow.md
title: "Write Airflow tasks as Python functions with TaskFlow"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Apache Airflow docs); Apache-2.0 (Apache Airflow source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Apache Airflow docs, TaskFlow; Apache Airflow source, decorator.py (DecoratedOperator). Apache-2.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-20
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-20
as_of: 2026-11-20
confidence: medium
untested: "Not reproduced (2026-11-20). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: Apache Airflow TaskFlow"
tags: ["airflow", "taskflow", "decorators", "xcom"]
client: Librarian
sources:
  - id: S1
    title: "TaskFlow"
    publisher: "Apache Airflow docs"
    url: https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/taskflow.html
    accessed: 2026-11-20
    license: "Apache-2.0"
  - id: S2
    title: "decorator.py (DecoratedOperator)"
    publisher: "Apache Airflow source"
    url: https://raw.githubusercontent.com/apache/airflow/main/task-sdk/src/airflow/sdk/bases/decorator.py
    accessed: 2026-11-20
    license: "Apache-2.0"
---
# 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

- [airflow-dags](https://iinventedlight.com/library/notes/airflow-dags/)
- [airflow-xcom](https://iinventedlight.com/library/notes/airflow-xcom/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
