Airflow Xcoms Guide
Filter by dag_id to see all current values stored for your DAG. Conclusion
# Task 1: push data to XCom task_1 = BashOperator( task_id='task_1', bash_command='echo "Hello, World!"', xcom_push_key='greeting', dag=dag, ) airflow xcoms
| Do’s | Don’ts | |------|--------| | ✅ Keep XComs < 10 KB | ❌ Store images, models, large JSON | | ✅ Use meaningful keys | ❌ Rely on default return_value for multiple values | | ✅ Pull once, reuse in memory | ❌ Call xcom_pull inside a loop | | ✅ Combine with explicit >> dependencies | ❌ Assume pulling implies execution order | | ✅ Use xcom_pull(task_ids=[...]) for multiple | ❌ Pull all XComs without filtering | Filter by dag_id to see all current values
| Aspect | Rating | Notes | |--------|--------|-------| | | ⭐⭐⭐⭐ | Zero extra setup – return values are automatically stored. | | DAG readability | ⭐⭐⭐⭐ | Data flow is explicit when using .xcom_pull() . | | Lightweight coordination | ⭐⭐⭐⭐⭐ | Perfect for passing IDs, flags, dates, small configs. | | Backend support | ⭐⭐⭐ | Works with any Airflow DB backend (Postgres, MySQL, SQLite, etc.). | | | Lightweight coordination | ⭐⭐⭐⭐⭐ | Perfect
def process_data(**kwargs): # Pull the value from the upstream task ti = kwargs['ti'] # We use xcom_pull with the task_ids retrieved_id = ti.xcom_pull(task_ids='extract_task') print(f"Processing file: retrieved_id")
with DAG('xcom_example', start_date=datetime(2023, 1, 1), schedule_interval=None) as dag:
