airflow.models.xcom

Module Contents

airflow.models.xcom.log[source]
airflow.models.xcom.MAX_XCOM_SIZE = 49344[source]
airflow.models.xcom.XCOM_RETURN_KEY = return_value[source]
class airflow.models.xcom.BaseXCom[source]

Bases: airflow.models.base.Base, airflow.utils.log.logging_mixin.LoggingMixin

Base class for XCom objects.

__tablename__ = xcom[source]
key[source]
value[source]
timestamp[source]
execution_date[source]
task_id[source]
dag_id[source]
dag_run[source]
run_id[source]
init_on_load(self)[source]

Called by the ORM after the instance has been loaded from the DB or otherwise reconstituted i.e automatically deserialize Xcom value when loading from DB.

__repr__(self)[source]
classmethod set(cls, key, value, task_id, dag_id, execution_date=None, run_id=None, session=None)[source]

Store an XCom value.

Returns

None

classmethod get_one(cls, execution_date: Optional[pendulum.DateTime] = None, run_id: Optional[str] = None, key: Optional[str] = None, task_id: Optional[Union[str, Iterable[str]]] = None, dag_id: Optional[Union[str, Iterable[str]]] = None, include_prior_dates: bool = False, session: Session = None)[source]

Retrieve an XCom value, optionally meeting certain criteria. Returns None of there are no results.

run_id and execution_date are mutually exclusive.

This method returns "full" XCom values (i.e. it uses deserialize_value from the XCom backend). Please use get_many() if you want the "shortened" value via orm_deserialize_value

Parameters
  • execution_date (pendulum.datetime) -- Execution date for the task

  • run_id (str) -- Dag run id for the task

  • key (str) -- A key for the XCom. If provided, only XComs with matching keys will be returned. To remove the filter, pass key=None.

  • task_id (str) -- Only XComs from task with matching id will be pulled. Can pass None to remove the filter.

  • dag_id (str) -- If provided, only pulls XCom from this DAG. If None (default), the DAG of the calling task is used.

  • include_prior_dates (bool) -- If False, only XCom from the current execution_date are returned. If True, XCom from previous dates are returned as well.

  • session (sqlalchemy.orm.session.Session) -- database session

classmethod get_many(cls, execution_date: Optional[pendulum.DateTime] = None, run_id: Optional[str] = None, key: Optional[str] = None, task_ids: Optional[Union[str, Iterable[str]]] = None, dag_ids: Optional[Union[str, Iterable[str]]] = None, include_prior_dates: bool = False, limit: Optional[int] = None, session: Session = None)[source]

Composes a query to get one or more values from the xcom table.

run_id and execution_date are mutually exclusive.

This function returns an SQLAlchemy query of full XCom objects. If you just want one stored value then use get_one().

Parameters
  • execution_date (pendulum.datetime) -- Execution date for the task

  • run_id (str) -- Dag run id for the task

  • key (str) -- A key for the XCom. If provided, only XComs with matching keys will be returned. To remove the filter, pass key=None.

  • task_ids (str or iterable of strings (representing task_ids)) -- Only XComs from tasks with matching ids will be pulled. Can pass None to remove the filter.

  • dag_ids (str) -- If provided, only pulls XComs from this DAG. If None (default), the DAG of the calling task is used.

  • include_prior_dates (bool) -- If False, only XComs from the current execution_date are returned. If True, XComs from previous dates are returned as well.

  • limit (int) -- If required, limit the number of returned objects. XCom objects can be quite big and you might want to limit the number of rows.

  • session (sqlalchemy.orm.session.Session) -- database session

classmethod delete(cls, xcoms, session=None)[source]

Delete Xcom

classmethod clear(cls, execution_date: Optional[pendulum.DateTime] = None, dag_id: str = None, task_id: str = None, run_id: str = None, session: Session = None)[source]

Clears all XCom data from the database for the task instance

run_id and execution_date are mutually exclusive.

Parameters
  • execution_date (pendulum.datetime or None) -- Execution date for the task

  • dag_id (str) -- ID of DAG to clear the XCom for.

  • task_id (str) -- Only XComs from task with matching id will be cleared.

  • run_id (str or None) -- Dag run id for the task

  • session (sqlalchemy.orm.session.Session) -- database session

static serialize_value(value: Any)[source]

Serialize Xcom value to str or pickled object

static deserialize_value(result: 'XCom')[source]

Deserialize XCom value from str or pickle object

orm_deserialize_value(self)[source]

Deserialize method which is used to reconstruct ORM XCom object.

This method should be overridden in custom XCom backends to avoid unnecessary request or other resource consuming operations when creating XCom orm model. This is used when viewing XCom listing in the webserver, for example.

airflow.models.xcom.resolve_xcom_backend()[source]
Resolves custom XCom class
airflow.models.xcom.XCom[source]

Was this entry helpful?