Retrieve Extra parameters from Airflow Connection

48 Views Asked by At

I have a Snowflake connection defined in Airflow.enter image description here

I am selecting the user, password and schema using the below:

conn = BaseHook.get_connection("snowflake_conn")
conn.login

return the login (EXAMPLE in this case)

If I try to access the 'extra' parameters, it doesn't work.

conn = BaseHook.get_connection("snowflake_conn")
conn.role

returns a AttributeError: 'Connection' object has no attribute 'role'

Is there any different way in which I could grab the extra parameters from Airflow Connection settings?

1

There are 1 best solutions below

0
Andrey Anshin On BEST ANSWER

Extra parameters stored into the extra field, for access to that parameters you need to convert it first from string to the python dictionary by use Connection.extra_dejson property

conn = BaseHook.get_connection("snowflake_conn")
conn.extra_dejson.get("role")