Skip to content
BENIBIX Learn

Airflow Operator

Data🗓️ OrchestrationApache Airflow

Also known as Operator (Airflow), BashOperator, PythonOperator

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

Think of it like

It is like a cookie cutter. You press it once for each cookie, and each cookie is a task.

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.

Definition

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 code

python
from airflow.providers.standard.operators.bash import BashOperator

load = BashOperator(
    task_id="load_orders",
    bash_command="python load_orders.py",
    retries=3,
)
This class is the template. Give it a task_id and a command, and it becomes the load_orders task.
The operator is the template at the top. Filled in, it becomes a task, and each run makes an instance of it.

Common mistake

Writing a new template class for a one-off step. A plain Python task is often simpler.

Key takeaways

  1. 1
    A template. Fill it in to make a task.
  2. 2
    One job each. Run a command, a query or a copy.
  3. 3
    From providers. Packages add operators for each service.

Compare