[portable] — Xcom Airflow
The use of XCom in Airflow provides several benefits:
| Feature | Description | |---------|-------------| | | String identifier (default: return_value ) | | Value | Any picklable Python object (JSON-serializable recommended) | | Task ID | Source task for pull | | DAG ID | Can pull from another DAG (requires access to its XCom table) | | Execution Date | Links XCom to a specific DAG run |
from datetime import datetime, timedelta from airflow import DAG from airflow.operators.bash_operator import BashOperator xcom airflow
[xcom] xcom_age = 0 # seconds (0 = keep forever) xcom_max_size = 1024 # in bytes (1 MB default)
You can manually trigger communication using the xcom_push and xcom_pull methods available on the task instance ( ti ) object. The use of XCom in Airflow provides several
In Airflow, each task has access to an XCOM object, which is used to store and retrieve data. When a task wants to share data with another task, it can use the xcom_push method to store the data in the XCOM object. The data is then available for other tasks to retrieve using the xcom_pull method.
✅
from airflow import DAG from airflow.operators.python import PythonOperator from datetime import datetime
Here are some examples of how XCom can be used in Airflow: The data is then available for other tasks