You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: airflow-core/docs/core-concepts/xcoms.rst
+16-22Lines changed: 16 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,10 +25,8 @@ XComs (short for "cross-communications") are a mechanism that let :doc:`tasks` t
25
25
26
26
An XCom is identified by a ``key`` (essentially its name), as well as the ``task_id`` and ``dag_id`` it came from. They can have any serializable value (including objects that are decorated with ``@dataclass`` or ``@attr.define``, see :ref:`TaskFlow arguments <concepts:arbitrary-arguments>`:), but they are only designed for small amounts of data; do not use them to pass around large values, like dataframes.
27
27
28
-
.. versionchanged:: 3.0
29
-
30
-
In Airflow 3.0+, XCom operations should be performed through the Task Context using
31
-
:func:`~airflow.sdk.get_current_context`. Direct database access is not possible.
28
+
XCom operations should be performed through the Task Context using
29
+
:func:`~airflow.sdk.get_current_context`. Direct database access is not possible.
32
30
33
31
XComs are explicitly "pushed" and "pulled" to/from their storage using the ``xcom_push`` and ``xcom_pull`` methods on Task Instances.
34
32
@@ -78,26 +76,24 @@ An example of pushing multiple XComs and pulling them individually:
78
76
# Pulling entire xcom data from push_multiple task
79
77
data = context["ti"].xcom_pull(task_ids="push_multiple", key="return_value")
80
78
81
-
.. versionchanged:: 3.0
82
-
83
-
In Airflow 3.0+, you can also use the Task Context directly for XCom operations:
79
+
You can also use the Task Context directly for XCom operations:
84
80
85
-
.. code-block:: python
81
+
.. code-block:: python
86
82
87
-
from airflow.sdk import get_current_context
83
+
from airflow.sdk import get_current_context
88
84
89
85
90
-
@task
91
-
defexample_task():
92
-
context = get_current_context()
93
-
ti = context["ti"]
86
+
@task
87
+
defexample_task():
88
+
context = get_current_context()
89
+
ti = context["ti"]
94
90
95
-
# Push XCom
96
-
ti.xcom_push(key="my_key", value="my_value")
91
+
# Push XCom
92
+
ti.xcom_push(key="my_key", value="my_value")
97
93
98
-
# Pull XCom
99
-
value = ti.xcom_pull(task_ids="previous_task", key="my_key")
100
-
return value
94
+
# Pull XCom
95
+
value = ti.xcom_pull(task_ids="previous_task", key="my_key")
96
+
return value
101
97
102
98
.. note::
103
99
@@ -117,10 +113,8 @@ The XCom system has interchangeable backends, and you can set which backend is b
117
113
118
114
If you want to implement your own backend, you should subclass :class:`~airflow.sdk.execution_time.xcom.XCom`, and override the ``serialize_value`` and ``deserialize_value`` methods.
119
115
120
-
.. versionchanged:: 3.0
121
-
122
-
The base class for custom XCom backends is now :class:`~airflow.sdk.execution_time.xcom.XCom`
123
-
from the airflow.sdk namespace.
116
+
The base class for custom XCom backends is now :class:`~airflow.sdk.execution_time.xcom.XCom`
117
+
from the airflow.sdk namespace.
124
118
125
119
You can override the ``purge`` method in the ``BaseXCom`` class to have control over purging the xcom data from the custom backend. This will be called as part of ``delete``.
0 commit comments