Operators
Operators define the work to be performed in a task. Airflow ships with a rich set of built‑in operators, and you can also create custom operators for your own logic.
Common Patterns
Below are snippets showing typical usage patterns for several operators.
# BashOperator example
from airflow import DAG
from airflow.providers.bash.operators.bash import BashOperator
from datetime import datetime
with DAG('example_bash', start_date=datetime(2023,1,1), schedule_interval='@daily') as dag:
t1 = BashOperator(
task_id='print_date',
bash_command='date'
)
# PythonOperator example
from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime
def greet():
print("Hello from Airflow!")
with DAG('example_python', start_date=datetime(2023,1,1), schedule_interval='@once') as dag:
greet_task = PythonOperator(
task_id='greet',
python_callable=greet
)