🗓️Airflow Hook
Also known as Hook (Airflow), PostgresHook, S3Hook
Code that logs in to one system for you, like a database. Tasks use it.
Think of it like
It is like a phone that already knows how to dial. You say who to call, and it does the rest.
Example
Lucy needs a query that no ready-made task offers. In her task she makes a PostgresHook with the shop_db connection. She runs the query in two lines.
Why it matters
It saves you from writing login and retry code for every system. The hook already knows how that system works.
Definition
Example code
python
from airflow.providers.postgres.hooks.postgres import PostgresHook
hook = PostgresHook(postgres_conn_id="shop_db")
rows = hook.get_records("SELECT COUNT(*) FROM orders")Common mistake
Key takeaways
- 1One system each. A hook per database or service.
- 2Uses a connection. Logs in by conn_id.
- 3Under operators. Operators are built from hooks.