Prefect 2.0
Orion allows you to run any Python code in your flow. Therefore, you can use the native Python if/else
statements to specify conditional logic. Here is an example:
from prefect import task, flow
@task
def get_color():
return "green"
@flow
def main_flow():
color = get_color().wait().result()
if color == "green":
print("Green light!")
else:
print(color)
if __name__ == "__main__":
main_flow()
Prefect 1.0
Prefect 1.0 provides special tasks allowing to build conditional logic. You can import those tasks (case
, merge
, ifelse
, switch
) from prefect.tasks.control_flow
.