Skip to content

Instantly share code, notes, and snippets.

@nathairtras
Last active September 27, 2017 00:44
Show Gist options
  • Save nathairtras/12e00f4dc5ba7ff3f89c77b86db2d923 to your computer and use it in GitHub Desktop.
Save nathairtras/12e00f4dc5ba7ff3f89c77b86db2d923 to your computer and use it in GitHub Desktop.
creating airflow connections via python
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