airflow.decorators.base
¶
Module Contents¶
Classes¶
Wraps a Python callable and captures args/kwargs when called for execution. |
|
MappedOperator implementation for @task-decorated task function. |
|
Declaration of a @task-decorated callable for type-checking. |
|
Type declaration for |
Functions¶
|
Generate unique task id given a DAG (or if run in a DAG context). |
|
Generate a wrapper that wraps a function into an Airflow operator. |
Attributes¶
- airflow.decorators.base.get_unique_task_id(task_id, dag=None, task_group=None)[source]¶
Generate unique task id given a DAG (or if run in a DAG context).
IDs are generated by appending a unique number to the end of the original task id.
- Example:
task_id task_id__1 task_id__2 … task_id__20
- class airflow.decorators.base.DecoratedOperator(*, python_callable, task_id, op_args=None, op_kwargs=None, multiple_outputs=False, kwargs_to_upstream=None, **kwargs)[source]¶
Bases:
airflow.models.baseoperator.BaseOperator
Wraps a Python callable and captures args/kwargs when called for execution.
- Parameters
python_callable (Callable) – A reference to an object that is callable
op_kwargs (Mapping[str, Any] | None) – a dictionary of keyword arguments that will get unpacked in your function (templated)
op_args (Collection[Any] | None) – a list of positional arguments that will get unpacked when calling your callable (templated)
multiple_outputs (bool) – If set to True, the decorated function’s return value will be unrolled to multiple XCom values. Dict will unroll to XCom values with its keys as XCom keys. Defaults to False.
kwargs_to_upstream (dict[str, Any] | None) – For certain operators, we might need to upstream certain arguments that would otherwise be absorbed by the DecoratedOperator (for example python_callable for the PythonOperator). This gives a user the option to upstream kwargs as needed.
- class airflow.decorators.base.DecoratedMappedOperator(context=None)[source]¶
Bases:
airflow.models.mappedoperator.MappedOperator
MappedOperator implementation for @task-decorated task function.
- class airflow.decorators.base.Task[source]¶
Bases:
airflow.typing_compat.Protocol
,Generic
[FParams
,FReturn
]Declaration of a @task-decorated callable for type-checking.
An instance of this type inherits the call signature of the decorated function wrapped in it (not exactly since it actually returns an XComArg, but there’s no way to express that right now), and provides two additional methods for task-mapping.
This type is implemented by
_TaskDecorator
at runtime.
- class airflow.decorators.base.TaskDecorator[source]¶
Bases:
airflow.typing_compat.Protocol
Type declaration for
task_decorator_factory
return type.
- airflow.decorators.base.task_decorator_factory(python_callable=None, *, multiple_outputs=None, decorated_operator_class, **kwargs)[source]¶
Generate a wrapper that wraps a function into an Airflow operator.
Can be reused in a single DAG.
- Parameters
python_callable (Callable | None) – Function to decorate.
multiple_outputs (bool | None) – If set to True, the decorated function’s return value will be unrolled to multiple XCom values. Dict will unroll to XCom values with its keys as XCom keys. If set to False (default), only at most one XCom value is pushed.
decorated_operator_class (type[airflow.models.baseoperator.BaseOperator]) – The operator that executes the logic needed to run the python function in the correct environment.
Other kwargs are directly forwarded to the underlying operator class when it’s instantiated.