Xcom In — Airflow ((top))
process_record(get_latest_record_id()) @task def produce_data(): return "ids": [1,2,3], "source": "api" @task def consume_one(data): return f"Got data['ids'][0]"
aggregate(download.expand(url=fetch_urls())) xcom in airflow
@task def extract() -> dict: return "user_id": 123, "name": "Alice" # pushed automatically dict: return "user_id": 123
@task def process(user_data: dict) -> str: return f"Processed user user_data['name']" xcom in airflow
process(extract()) # XCom passed implicitly
from airflow.decorators import dag, task from datetime import datetime @dag(start_date=datetime(2024,1,1), schedule=None, catchup=False) def xcom_demo():
push = PythonOperator(task_id='push_task', python_callable=push_function) pull = PythonOperator(task_id='pull_task', python_callable=pull_function)