airflow.providers.odbc.hooks.odbc

This module contains ODBC hook.

Module Contents

Classes

OdbcHook

Interact with odbc data sources using pyodbc.

Attributes

DEFAULT_ODBC_PLACEHOLDERS

airflow.providers.odbc.hooks.odbc.DEFAULT_ODBC_PLACEHOLDERS[source]
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 in hook_params dictionary when instantiating hook by SQL operators.

  • set driver extra in the connection and set allow_driver_in_extra to True in section providers.odbc section of airflow config.

  • patch OdbcHook.default_driver in local_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 for get_sqlalchemy_engine and get_sqlalchemy_connection methods.

  • kwargs – passed to DbApiHook

property connection[source]

The Connection object with ID odbc_conn_id.

property database: str | None[source]

Database provided in init if exists; otherwise, schema from Connection object.

property sqlalchemy_scheme: str[source]

SQLAlchemy scheme either from constructor, connection extras or default.

property connection_extra_lower: dict[source]

connection.extra_dejson but where keys are converted to lower case.

This is used internally for case-insensitive access of odbc params.

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 representing ApplicationIntent=ReadOnly. Any key-value pairs provided in Connection.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.

property placeholder[source]
DEFAULT_SQLALCHEMY_SCHEME = 'mssql+pyodbc'[source]
conn_name_attr = 'odbc_conn_id'[source]
default_conn_name = 'odbc_default'[source]
conn_type = 'odbc'[source]
hook_name = 'ODBC'[source]
supports_autocommit = True[source]
default_driver: str | None[source]
get_conn()[source]

Return pyodbc connection object.

get_uri()[source]

URI invoked in get_sqlalchemy_engine().

get_sqlalchemy_connection(connect_kwargs=None, engine_kwargs=None)[source]

SQLAlchemy connection object.

Was this entry helpful?