Skip to content
BENIBIX Learn

Airflow Hook vs Operator

People think a hook is just another kind of operator. A hook is a helper that logs in to one system and talks to it. It is not a task and never shows in the graph. An operator is a task. Many operators use a hook inside to do their work. When no operator fits, you call the hook from your own task.

Data🗓️ Orchestration

Airflow Hook

Code that logs in to one system for you, like a database. Tasks use it.

An Airflow hook is ready-made code for talking to one outside system. There is one for PostgreSQL, one for Amazon S3 and many more. You give it a connection name, and it logs in for you. Then you call its methods to run a query or move a file. Many operators are built on top of a hook. You use a hook directly when no operator does quite what you need.

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.
Full entry
Data🗓️ Orchestration

Airflow Operator

A ready-made Airflow template. Fill it in, and it becomes a task.

An Airflow operator is a ready-made template for one kind of task. One runs a shell command, one runs SQL, and one copies a file to the cloud. You fill in its settings and give it a task ID. That makes a task. Add-on packages bring templates for clouds, databases and tools. A sensor is a special one that waits.

Example
Lucy's DAG uses a SQL operator to build a table and an email operator to send the result. She writes no glue code.
Why it matters
Ready-made templates save you from writing the same code to connect again and again. A huge set of them is a big part of why Airflow spread.
Full entry

In one line

Airflow Hook
Code that logs in to one system for you, like a database. Tasks use it.
Airflow Operator
A ready-made Airflow template. Fill it in, and it becomes a task.