Skip to main content

Conditional and dynamic workflows

In flytekit, ConditionalSection (defined in flytekit/core/condition.py) builds branch blocks inside a workflow. Use it when different inputs should follow different task paths.

from flytekit.core.condition import ConditionalSection, conditional

ConditionalSection.start_branch() records each Case, and end_branch() either pops the branch context (last case) or returns the next Condition. For local execution, LocalExecutedConditionalSection evaluates expressions immediately via c.expr.eval().

Dynamic workflows differ at compile time: conditions compile to BranchNode structures with IfElseBlock, while dynamic workflows generate tasks at runtime.

Pass if_(expr).then(...) within a workflow context; ConditionalSection requires FlyteContextManager.push_context() when initialized.