airflow.models.xcom_arg

Module Contents

class airflow.models.xcom_arg.XComArg(operator: BaseOperator, key: str = XCOM_RETURN_KEY)[source]

Bases: airflow.models.taskmixin.TaskMixin

Class that represents a XCom push from a previous operator. Defaults to “return_value” as only key.

Current implementation supports

xcomarg >> op xcomarg << op op >> xcomarg (by BaseOperator code) op << xcomarg (by BaseOperator code)

Example: The moment you get a result from any operator (decorated or regular) you can

any_op = AnyOperator()
xcomarg = XComArg(any_op)
# or equivalently
xcomarg = any_op.output
my_op = MyOperator()
my_op >> xcomarg

This object can be used in legacy Operators via Jinja.

Example: You can make this result to be part of any generated string

any_op = AnyOperator()
xcomarg = any_op.output
op1 = MyOperator(my_text_message=f"the value is {xcomarg}")
op2 = MyOperator(my_text_message=f"the value is {xcomarg['topic']}")
Parameters
operator[source]

Returns operator of this XComArg.

roots[source]

Required by TaskMixin

leaves[source]

Required by TaskMixin

key[source]

Returns keys of this XComArg

__eq__(self, other)[source]
__getitem__(self, item)[source]

Implements xcomresult[‘some_result_key’]

__str__(self)[source]

Backward compatibility for old-style jinja used in Airflow Operators

Example: to use XComArg at BashOperator:

BashOperator(cmd=f"... { xcomarg } ...")
Returns

set_upstream(self, task_or_task_list: Union[TaskMixin, Sequence[TaskMixin]])[source]

Proxy to underlying operator set_upstream method. Required by TaskMixin.

set_downstream(self, task_or_task_list: Union[TaskMixin, Sequence[TaskMixin]])[source]

Proxy to underlying operator set_downstream method. Required by TaskMixin.

resolve(self, context: Dict)[source]

Pull XCom value for the existing arg. This method is run during op.execute() in respectable context.

Was this entry helpful?