Xcom | Airflow
def pull_function(**context): value = context['ti'].xcom_pull(key='message', task_ids='push_task') print(f"Received: value")
push >> pull
Here’s a technical write-up on — covering what it is, how it works, use cases, limitations, and best practices. XCom in Apache Airflow: Cross-Communication Between Tasks 1. Overview In Apache Airflow, each task instance is typically isolated. Tasks cannot share variables or data directly. XCom (short for cross-communication ) is the mechanism that allows tasks to exchange small pieces of data. xcom airflow
with DAG(dag_id='xcom_demo', start_date=datetime(2024,1,1), schedule_interval=None) as dag: def pull_function(**context): value = context['ti']
Received: Hello from Task 1 3. Return Values as Implicit XComs If a Python callable returns a value, Airflow automatically pushes it under the key return_value . task_ids='push_task') print(f"Received: value") push >
push = PythonOperator(task_id='push_task', python_callable=push_function) pull = PythonOperator(task_id='pull_task', python_callable=pull_function)