airflow.providers.standard.operators.branch

Branching operators.

Classes

BranchMixIn

Utility helper which handles the branching as one-liner.

BaseBranchOperator

A base class for creating operators with branching functionality, like to BranchPythonOperator.

Module Contents

class airflow.providers.standard.operators.branch.BranchMixIn(context=None)[source]

Bases: airflow.providers.standard.utils.skipmixin.SkipMixin

Utility helper which handles the branching as one-liner.

do_branch(context, branches_to_execute)[source]

Implement the handling of branching including logging.

class airflow.providers.standard.operators.branch.BaseBranchOperator(**kwargs)[source]

Bases: airflow.models.baseoperator.BaseOperator, BranchMixIn

A base class for creating operators with branching functionality, like to BranchPythonOperator.

Users should create a subclass from this operator and implement the function choose_branch(self, context). This should run whatever business logic is needed to determine the branch, and return one of the following: - A single task_id (as a str) - A single task_group_id (as a str) - A list containing a combination of task_ids and task_group_ids

The operator will continue with the returned task_id(s) and/or task_group_id(s), and all other tasks directly downstream of this operator will be skipped.

inherits_from_skipmixin = True[source]

Used to determine if an Operator is inherited from SkipMixin or its subclasses (e.g., BranchMixin).

abstract choose_branch(context)[source]

Abstract method to choose which branch to run.

Subclasses should implement this, running whatever logic is necessary to choose a branch and returning a task_id or list of task_ids.

Parameters:

context (airflow.sdk.definitions.context.Context) – Context dictionary as passed to execute()

execute(context)[source]

Derive when creating an operator.

Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

Was this entry helpful?