airflow.hooks.base_hook

Base class for all hooks

Module Contents

airflow.hooks.base_hook.CONN_ENV_PREFIX = AIRFLOW_CONN_[source]
class airflow.hooks.base_hook.BaseHook[source]

Bases: airflow.utils.log.logging_mixin.LoggingMixin

Abstract base class for hooks, hooks are meant as an interface to interact with external systems. MySqlHook, HiveHook, PigHook return object that can handle the connection and interaction to specific instances of these systems, and expose consistent methods to interact with them.

classmethod _get_connections_from_db(cls, conn_id, session=None)[source]
classmethod _get_connection_from_env(cls, conn_id)[source]
classmethod get_connections(cls, conn_id:str)[source]

Get all connections as an iterable.

:param conn_id connection id :return array of connections

classmethod get_connection(cls, conn_id:str)[source]

Get random connection selected from all connections configured with this connection id.

:param conn_id connection id :return connection

classmethod get_hook(cls, conn_id:str)[source]

Returns default hook for this connection id. :param conn_id: connection id :return: default hook for this connection

get_conn(self)[source]

Returns connection for the hook.

get_records(self, sql)[source]

Returns records for the sql query (for hooks that support SQL).

get_pandas_df(self, sql)[source]

Returns pandas dataframe for the sql query (for hooks that support SQL).

run(self, sql)[source]

Runs SQL query (for hooks that support SQL).