I am able to access the macros in python code like below:
partition_dt = macros.ds_add(ds, 1)
But i am not able to figure out how to get hold of the ds
variable itself which seemingly can only be accessed in templates. Any pointers?
I assume you want to call one of the default variables built-in AirFlow ds - the execution date as YYYY-MM-DD
To call just ds, you can do:
EXEC_DATE = '{{ ds }}'
To call what you wanted - macros.ds_add:
EXEC_DATE = '{{ macros.ds_add(ds, 1) }}'
And load it this way:
T1 = BashOperator(\
task_id='test_ds',
bash_command='echo ' + EXEC_DATE
dag=DAG)
In case you want to format it (like I had to), you can do:
EXEC_DATE = '{{ macros.ds_format(macros.ds_add(ds, 1), "%Y-%m-%d", "%Y%m%d") }}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With