# Airflow TaskFlow API

> Airflow tasks written as plain Python code, with @task on top.

**Field:** Data Engineering  
**Category:** Orchestration  
**Also known as:** TaskFlow API, TaskFlow, Airflow @task Decorator

## Think of it like

It is like passing a note straight to the next person in line. Nobody has to post it on a board first.

## Definition

The TaskFlow API is a way to write Airflow tasks as plain Python functions. You put @task above a function, and it becomes a task. When one task's function returns a value, the next task gets it as an input. Airflow stores the value as an XCom for you, so you never call XCom by hand. Calling one function inside another also sets the order of the tasks.

## Example

Lucy writes extract and load as two functions with @task. She writes load(extract()), and Airflow runs extract first and hands its rows to load.

## Example code

```python
@task
def extract():
    return {"1001": 301.27}

@task
def load(rows):
    print(rows)

load(extract())
```

Two functions become two tasks. The value extract returns is handed to load.

## Why it matters

It makes a DAG read like normal Python. Passing data between tasks takes one line, not a pair of XCom calls.

## Common mistake

Returning a whole table from a task. The value is kept in Airflow's database, so pass a file path.

## Three principles

- **Plain functions.** @task turns one into a task.
- **Values flow on.** Return values become inputs.
- **Order from calls.** Calling a task sets the order.

## Related terms

- [Apache Airflow](https://learn.benibix.com/term/data/apache-airflow)
- [Airflow Task](https://learn.benibix.com/term/data/airflow-task)
- [Airflow XCom](https://learn.benibix.com/term/data/airflow-xcom)
- [Airflow DAG](https://learn.benibix.com/term/data/airflow-dag)
- [Workflow as Code](https://learn.benibix.com/term/data/workflow-as-code)
- [Python](https://learn.benibix.com/term/development/python)

![A code file called daily_sales.py on the left defines two functions, extract and load, each marked @task, and calls load(extract()). An arrow leads to a graph on the right: an extract box, then a highlighted load box, with a note that the return value is handed on.](https://learn.benibix.com/diagrams/dat2-workflow-as-code.svg)

---

Source: https://learn.benibix.com/term/data/airflow-taskflow-api
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
