📌 Most Useful Airflow Template Variables
🧩 Task Instance Context
| Variable | Meaning |
|---|---|
ti |
The TaskInstance object. Commonly used. |
task_instance |
Same as ti — full TaskInstance object. |
task |
The task object (operator instance). |
task_instance_key_str |
Unique identifier for this task instance (DAG ID + task ID + run date). |
Example usage:
🗓️ Execution Time / Dates
| Variable | Meaning |
|---|---|
ds |
Execution date as YYYY-MM-DD. |
ds_nodash |
Execution date as YYYYMMDD. |
ts |
Execution timestamp (ISO8601). |
ts_nodash |
Timestamp without dashes. |
logical_date |
Pendulum datetime of the logical (scheduled) execution date (same as execution_date). |
next_ds |
Next execution date (string). |
prev_ds |
Previous execution date (string). |
next_execution_date |
Next logical execution datetime. |
prev_execution_date |
Previous logical execution datetime. |
macros.* |
All Airflow macro helpers. |
Example:
🧳 DAG-related
| Variable | Meaning |
|---|---|
dag |
The DAG object. |
dag_run |
The DAGRun object (contains run_id, conf, etc.). |
run_id |
The DAG run ID (e.g., manual__2024-01-01T00:00:00+00:00). |
conf |
Runtime config passed via REST UI/trigger (a dict). |
params |
DAG-level params. |
Example (pull config values):
🔄 Data Intervals (Airflow 2.2+)
Airflow newer versions use data intervals:
| Variable | Meaning |
|---|---|
data_interval_start |
Start of data interval (Pendulum datetime). |
data_interval_end |
End of data interval. |
🔧 Macros (helpers)
Airflow provides many helpers under macros.
Common ones:
| Macro | Meaning |
|---|---|
macros.ds_add(ds, n) |
Add n days to a date. |
macros.ds_format(ds, input_fmt, output_fmt) |
Transform date format. |
macros.datetime |
Python datetime module. |
macros.timedelta |
Python timedelta. |
macros.uuid() |
Random UUID string. |
Example:

浙公网安备 33010602011771号