Process Flow - Pushing and pulling XCom values
Task A runs
Push XCom value
Task B waits
Pull XCom value
Task B uses value
This flow shows how one task pushes a value to XCom and another task pulls it later to use.
def task_a(ti): ti.xcom_push(key='my_key', value='hello') def task_b(ti): val = ti.xcom_pull(key='my_key', task_ids='task_a') print(val)
| Step | Action | XCom State | Output |
|---|---|---|---|
| 1 | Task A starts | {} | |
| 2 | Task A pushes key='my_key', value='hello' | {"task_a": {"my_key": "hello"}} | |
| 3 | Task A finishes | {"task_a": {"my_key": "hello"}} | |
| 4 | Task B starts | {"task_a": {"my_key": "hello"}} | |
| 5 | Task B pulls key='my_key' from task_a | {"task_a": {"my_key": "hello"}} | hello |
| 6 | Task B prints pulled value | {"task_a": {"my_key": "hello"}} | hello |
| 7 | Task B finishes | {"task_a": {"my_key": "hello"}} |
| Variable | Start | After Step 2 | After Step 5 | Final |
|---|---|---|---|---|
| XCom | {} | {"task_a": {"my_key": "hello"}} | {"task_a": {"my_key": "hello"}} | {"task_a": {"my_key": "hello"}} |
| val (in task_b) | None | None | 'hello' | 'hello' |
XCom lets tasks share small data. Task pushes with ti.xcom_push(key, value). Other tasks pull with ti.xcom_pull(key, task_ids). Pull needs task_ids to find the right task's data. XCom values persist between tasks in the same DAG run.