Airflow Xcom Example //free\\ Jun 2026

4/4 ✅ Best use cases:

Inside generate_data , we use kwargs['ti'] . This gives us access to the Task Instance. We specifically call xcom_push with a custom key 'random_number' . This is useful when a single task needs to push multiple different values. airflow xcom example

Think of it like a secret note passed between two students sitting on opposite sides of the classroom. One student writes the note (Push), leaves it on the teacher's desk (the Metadata Database), and the other student picks it up (Pull). 4/4 ✅ Best use cases: Inside generate_data ,

🧵

from airflow.decorators import dag, task from pendulum import datetime @dag(start_date=datetime(2023, 1, 1), schedule=None, catchup=False) def xcom_taskflow_dag(): @task def generate_value(): # This return value is automatically pushed to XCom return "order_id": 1234, "status": "processed" @task def process_value(order_data): # Airflow automatically pulls the XCom data here print(f"Processing order: order_data['order_id']") # Setting the dependency naturally passes the data order_info = generate_value() process_value(order_info) xcom_taskflow_dag() Use code with caution. The Traditional Way: Explicit Push/Pull This is useful when a single task needs