Jinja Expressions
Jinja expressions
In Airflow, Jinja templating is the "glue" that allows your static code to understand the dynamic flow of time. Instead of hardcoding a date, you use these macros to tell the worker: "Look at the specific time bucket you are currently processing."
Here are the most important macros you will use in Airflow 3.x.
The "Big Three" (Current Standard)
These are the most common macros. They refer to the Data Interval (the bucket of time being processed).
Macro
Description
Output Example (for Feb 4, 2026)
{{ ds }}
The "Datestamp" (String). The start of the interval.
2026-02-04
{{ ds_nodash }}
Same as ds, but without dashes.
20260204
{{ logical_date }}
The full Pendulum/DateTime object of the start.
2026-02-04T00:00:00+00:00
The Interval Boundaries
As you learned in the "Incremental Processing" section, Airflow defines a window with a start and an end.
{{ data_interval_start }}: The beginning of the period. (Same aslogical_date).{{ data_interval_end }}: The end of the period. (In a@dailyDAG, this is exactly 24 hours after the start).
Why use data_interval_end?
If you are querying a database, you usually want all records where:
created_at >= '{{ data_interval_start }}' AND created_at < '{{ data_interval_end }}'
Formatting and Manipulation (The Pipes)
Airflow macros are based on Jinja, which allows you to use "filters" (the | symbol) to change how the date looks.
Custom Formatting:
{{ logical_date.format('YYYY/MM/DD') }}→2026/02/04Time Arithmetic:
Because these are Pendulum objects, you can do math directly in the template:
{{ logical_date.add(days=-7) | ds }}→2026-01-28(One week ago).
Special Case: "Now" vs. "Then"
It is very common for beginners to confuse the Processing Time with the Execution Time.
{{ logical_date }}: The time the data belongs to (e.g., Feb 4th).{{ ts }}: The "Timestamp." Similar to logical date but in ISO 8601 format.{{ macros.datetime.now() }}: The actual, real-world time right now. Avoid using this for data processing! If you use "now" and have to re-run a job from last week, "now" will point to today, causing your data to be wrong.
How to test them quickly
Remember that airflow tasks render command we discussed? This is exactly what it’s for.
If you have a task in your 01_download_rocket_launches DAG, run this in your terminal:
Airflow won't run the task; it will just show you exactly what the {{ ds }} and other macros would turn into for that date. It's the best way to catch typos before you run your code.
Last updated