from airflow.models import Variable db_connection = Variable.get('database_connection_str') # perform some database operation using the db_connection
from airflow.models import DAG from airflow.operators.bash_operator import BashOperator from datetime import datetime dag = DAG(dag_id='my_dag', start_date=datetime.now()) create_table_task = BashOperator( task_id='create_sql_table', bash_command='mysql -uroot -p{{ var.value.database_password }} -h{{ var.value.database_host }} -e "CREATE TABLE IF NOT EXISTS my_table (id int primary key, name varchar(50))"', dag=dag )In the above example, we are using Airflow variable to set password and host for database connection required for the BashOperator. Package Library: Airflow models Variable get method is part of the airflow.models package.