Store and access password using Apache airflow

You can store the password in a Hook – this will be encrypted so long as you have setup your fernet key.

Here is how you can create a connection via the UI:

Main Menu
Then:
Create Connection

To access this password:

from airflow.hooks.base_hook import BaseHook  # Deprecated in Airflow 2

connection = BaseHook.get_connection("username_connection")
password = connection.password # This is a getter that returns the unencrypted password.

Update since Airflow 2 launch

The library airflow.hooks.base_hook has been deprecated and you must use airflow.hooks.base instead.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)