airflow.providers.odbc.hooks.odbc
¶
This module contains ODBC hook.
Module Contents¶
Classes¶
Interact with odbc data sources using pyodbc. |
- class airflow.providers.odbc.hooks.odbc.OdbcHook(*args, database=None, driver=None, dsn=None, connect_kwargs=None, sqlalchemy_scheme=None, **kwargs)[source]¶
Bases:
airflow.providers.common.sql.hooks.sql.DbApiHook
Interact with odbc data sources using pyodbc.
- To configure driver, in addition to supplying as constructor arg, the following are also supported:
set
driver
parameter inhook_params
dictionary when instantiating hook by SQL operators.set
driver
extra in the connection and setallow_driver_in_extra
to True in sectionproviders.odbc
section of airflow config.patch
OdbcHook.default_driver
inlocal_settings.py
file.
See ODBC Connection for full documentation.
- Parameters
args – passed to DbApiHook
database (str | None) – database to use – overrides connection
schema
driver (str | None) – name of driver or path to driver. see above for more info
dsn (str | None) – name of DSN to use. overrides DSN supplied in connection
extra
connect_kwargs (dict | None) – keyword arguments passed to
pyodbc.connect
sqlalchemy_scheme (str | None) – Scheme sqlalchemy connection. Default is
mssql+pyodbc
Only used forget_sqlalchemy_engine
andget_sqlalchemy_connection
methods.kwargs – passed to DbApiHook
- property database: str | None[source]¶
Database provided in init if exists; otherwise,
schema
fromConnection
object.
- property sqlalchemy_scheme: str[source]¶
SQLAlchemy scheme either from constructor, connection extras or default.
- property driver: str | None[source]¶
Driver from init param if given; else try to find one in connection extra.
- property dsn: str | None[source]¶
DSN from init param if given; else try to find one in connection extra.
- property odbc_connection_string[source]¶
ODBC connection string.
We build connection string instead of using
pyodbc.connect
params because, for example, there is no param representingApplicationIntent=ReadOnly
. Any key-value pairs provided inConnection.extra
will be added to the connection string.
- property connect_kwargs: dict[source]¶
Effective kwargs to be passed to
pyodbc.connect
.The kwargs are merged from connection extra,
connect_kwargs
, and the hook’s init arguments. Values received to the hook precede those from the connection.If
attrs_before
is provided, keys and values are converted to int, as required by pyodbc.
- get_sqlalchemy_engine(engine_kwargs=None)[source]¶
Get an sqlalchemy_engine object.
- Parameters
engine_kwargs – Kwargs used in
create_engine()
.- Returns
the created engine.
- get_uri()[source]¶
URI invoked in
get_sqlalchemy_engine()
.