

If you're installing an Airflow version >=1.10.3, you can also return a list of task ids, allowing you to skip multiple downstream paths in a single Operator and don't have to use a dummy task before joining.Īll operators have a trigger_rule argument which defines the rule by which the generated task get triggered. If you want to skip some tasks, keep in mind that you can’t have an empty path, if so make a dummy task.Ī_task = DummyOperator(task_id='branch_a', dag=dag)ī_task = DummyOperator(task_id='branch_false', dag=dag) The task_id returned by the Python function has to be referencing a task directly downstream from the BranchPythonOperator task. The task_id returned is followed, and all of the other paths are skipped. The BranchPythonOperator is much like the PythonOperator except that it expects a python_callable that returns a task_id. Airflow 1.xĪirflow has a BranchPythonOperator that can be used to express the branching dependency more directly. You can also inherit directly from BaseBranchOperator overriding the choose_branch method, but for simple branching logic the decorator is best. Return "big_task" # run just this one task, skip all else Xcom_value = int(ti.xcom_pull(task_ids="start_task")) These paths can’t move forward.Airflow provides a branching decorator that allows you to return the task_id (or list of task_ids) that should run: branch_func(ti): Or directly downstream tasks are marked with a state of skipped so that Should point to a task directly downstream from. It derives the PythonOperator and expects a Python function that returnsĪ single task_id or list of task_ids to follow. BranchPythonOperator ( *, python_callable : Callable, op_args : Optional ] = None, op_kwargs : Optional ] = None, templates_dict : Optional = None, templates_exts : Optional ] = None, ** kwargs ) ¶īases: PythonOperator, Īllows a workflow to “branch” or follow a path following the execution determine_kwargs ( self, context : Mapping ) → Mapping ¶ execute_callable ( self ) ¶Ĭalls the python callable with the given arguments. Refer to get_template_context for more context. This is the main method to derive when creating an operator.Ĭontext is the same dictionary used as when rendering jinja templates. Template_fields = ¶ template_fields_renderers ¶ BLUE = #ffefeb ¶ ui_color ¶ shallow_copy_attrs = ¶ execute ( self, context : Dict ) ¶ Processing templated fields, for examples

Templates_exts ( list ) – a list of file extensions to resolve while In your callable’s context after the template has been applied. _init_ and execute takes place and are made available Will get templated by the Airflow engine sometime between Templates_dict ( dict ) – a dictionary where the values are templates that

Op_args ( list ( templated )) – a list of positional arguments that will get unpacked when Op_kwargs ( dict ( templated )) – a dictionary of keyword arguments that will get unpacked PythonOperator ( *, python_callable : Callable, op_args : Optional ] = None, op_kwargs : Optional ] = None, templates_dict : Optional = None, templates_exts : Optional ] = None, ** kwargs ) ¶ĭef my_python_callable ( ** kwargs ): ti = kwargs next_ds = kwargs Parameters Dict will unroll to xcom values with keys as keys.Ĭlass. Multiple_outputs ( bool) – if set, function return value will be Op_args ( list) – a list of positional arguments that will get unpacked when Op_kwargs ( dict) – a dictionary of keyword arguments that will get unpacked Python_callable ( python callable) – A reference to an object that is callable Please use the following instead:įrom corators import my_task() Parameters task ( python_callable : Optional = None, multiple_outputs : Optional = None, ** kwargs ) ¶Īn Airflow task. Obtain the execution context for the currently executing operator withoutĪ. Task(python_callable: Optional = None, multiple_outputs: Optional = None, **kwargs)ĭeprecated function that calls and allows users to turn a python function into
