| 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 |
One of the most powerful features of XComs is that they are accessible in Jinja templates. This allows you to pass runtime data into operators that don't necessarily support Python callables easily. airflow xcoms
def pull_specific_value(**kwargs): ti = kwargs['ti'] # Pull specific keys file = ti.xcom_pull(task_ids='push_task', key='file_name') count = ti.xcom_pull(task_ids='push_task', key='row_count') print(f"file has count rows.") | Do’s | Don’ts | |------|--------| | ✅
with DAG('xcom_example', start_date=datetime(2023, 1, 1), schedule_interval=None) as dag: 10 KB | ❌ Store images