How can I define a flow?

Prefect 2.0

To create a flow, add a @flow decorator to your function.

from prefect import flow

@flow
def flow_function_name():
    pass

Flows are uniquely identified by name. The above flow will be named flow_function_name. You can provide a custom name to your flow by using the name argument:

from prefect import flow

@flow(name="Sales report ELT")
def your_flow_function():
    pass

Prefect 1.0

Prefect 1.0 uses a context manager to define a Flow object constructing a DAG.

from prefect import Flow

with Flow("flow name") as flow:
    # defining the DAG structure here

Just to clarify, is the following (copied from above) Prefect 2.0?

from prefect import flow

@flow
def flow_function_name():
    return

Also, maybe this is already posted somewhere, but I wanted to add Prefect: Zero to Hero - Prefect is a great intro to using Prefect v1.0’s Flow!

1 Like

Correct. I thought that this would be obvious (and will be the default soon enough) but if this wasn’t clear to you, I’ll add a headline to each of those topics saying that it’s for 2.0 to make the distinction clearer

1 Like

As requested, added this post

1 Like