airflow.providers.odbc.hooks.odbc¶
This module contains ODBC hook.
Classes¶
Interact with odbc data sources using pyodbc. |
Module Contents¶
- 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.DbApiHookInteract with odbc data sources using pyodbc.
- To configure driver, in addition to supplying as constructor arg, the following are also supported:
set
driverparameter inhook_paramsdictionary when instantiating hook by SQL operators.set
driverextra in the connection and setallow_driver_in_extrato True in sectionproviders.odbcsection of airflow config.patch
OdbcHook.default_driverinlocal_settings.pyfile.
See ODBC Connection for full documentation.
- Parameters:
args – passed to DbApiHook
database (str | None) – database to use – overrides connection
schemadriver (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
extraconnect_kwargs (dict | None) – keyword arguments passed to
pyodbc.connectsqlalchemy_scheme (str | None) – Scheme sqlalchemy connection. Default is
mssql+pyodbcOnly used forget_sqlalchemy_engineandget_sqlalchemy_connectionmethods.kwargs – passed to DbApiHook
- property database: str | None[source]¶
Database provided in init if exists; otherwise,
schemafromConnectionobject.
- 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.connectparams because, for example, there is no param representingApplicationIntent=ReadOnly. Any key-value pairs provided inConnection.extrawill 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_beforeis 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().