There are several approaches to solving this, but first, you should simplify how you are accessing the timestamp.
As you are using Airflow, where execution_date is a pendulum.Pendulum object, you have access to the execution_date.int_timestamp property.
In a more general situation assuming you are using Python 3.3+ there is a simpler way to get the epoch timestamp using the timestamp() method on a datetime object (which is also available on a Pendulum object).
execution_date.int_timestamp
Output => 1555477775
Python 3.3+:
int(execution_date.timestamp())
Output => 1555477775
Python 2.7+:
int(v.strftime('%s'))
Output => 1555477775
1. Direct formatting within the template
This method uses the timestamp() method of the datetime object to generate a float which then run through the built-in int filter of the Jinja2 template.
For Pendulum:
{{ execution_date.int_timestamp }}
For general datetime objects:
{{ execution_date.timestamp()|int }}
2. Create a custom Jinja2 Filter
If you are using this transformation in multiple places throughout your templates, it is probably worth creating a filter to centralise this. With Airflow, you can register a custom filter on the DAG object.
import time
def epoch_int(v):
return int(v.strftime('%s'))
dag = DAG(
...
user_defined_filters={
"epoch_int": epoch_int,
}
...
)
and then use it in your template.
{{ execution_date|epoch_int }}