Lesson 5 / 25

Operators and Providers

Use built-in and provider operators and know when to prefer the TaskFlow decorator.

Templates for tasks

An operator is a reusable template for a kind of work: BashOperator runs a shell command, PythonOperator calls a function, EmptyOperator is a placeholder, and provider packages add operators for external systems (apache-airflow-providers-amazon, -google, -postgres, -snowflake, -cncf-kubernetes, and many more). Install only the providers you need. In Airflow 3 the core "standard" operators live in airflow.providers.standard, so imports differ from Airflow 2; always follow the documentation for your version.

Tasks and the arrows between them

A DAG file declares tasks and dependencies; the shape of the graph is the plan of the run.

Four tools: operators, TaskFlow, dependencies, schedule.
Figure 2.1 — Operators, TaskFlow, dependencies and schedule.

Imports: Airflow 3 vs 2

The same DAG needs different imports depending on the major version. Pick the block that matches the version you installed.

# Airflow 3.x
from airflow.sdk import DAG, dag, task
from airflow.providers.standard.operators.bash import BashOperator
from airflow.providers.standard.operators.python import PythonOperator

# Airflow 2.x
# from airflow import DAG
# from airflow.decorators import dag, task
# from airflow.operators.bash import BashOperator
# from airflow.operators.python import PythonOperator

Prefer the specialised operator

A provider operator for your warehouse or cloud service handles connections, retries and idempotent behaviour better than a hand-written BashOperator that shells out to a CLI.

Quick check: What do provider packages add to Airflow?

  • A new database
  • Operators, hooks and sensors for external systems
  • Faster CPUs
  • Browser themes
Answer

Operators, hooks and sensors for external systems — Providers package the integrations for clouds, databases and tools.