Last active
September 27, 2017 00:44
-
-
Save nathairtras/12e00f4dc5ba7ff3f89c77b86db2d923 to your computer and use it in GitHub Desktop.
creating airflow connections via python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from airflow import settings | |
from airflow.hooks import BaseHook | |
from airflow.models import Connection | |
# Start a session | |
session = settings.Session() | |
# Create a new connection - these are not unique by name! | |
cnx_kwargs = { | |
"conn_id": "mssql_named", | |
"conn_type": "mssql", | |
"host": "hostname", | |
"login": "airflow", | |
"password": "pass", | |
"schema": "db", | |
"port": "1433" | |
} | |
cnx = Connection(**cnx_kwargs) | |
session.add(cnx) | |
session.commit() | |
# Deletes the connection | |
session.delete(cnx) | |
session.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment