https://prefect.io logo
Title
d

darshan darshan

04/15/2023, 9:56 AM
Hi, How to create a flow in prefect 2.0? I was using create_flow_run from prefect.tasks.prefect.flow_run in prefect 1.0 ?
n

Nate

04/16/2023, 1:21 AM
hi @darshan darshan in prefect 2, you can create a flow like this:
from prefect import flow, task

@task
def say(message: str):
    print(message) # note this logged since tasks inherit log_prints=True

@flow(name="hello-prefect", log_prints=True)
def hello_world_flow(message: str):
    say(message)

# and run it 
if __name__ == "__main__":
    hello_world_flow('hi from earth!')
and then if you want to deploy this and then create a flow run of it, you can: • use the cli
prefect deployment run 'hello-prefect/first-deployment-name'
• use the python api
from prefect.deployments import run_deployment

run_deployment(name='hello-prefect/first-deployment-name')
d

darshan darshan

04/16/2023, 7:10 AM
thanks @Nate
How can i create a flow with a dynamic flow name
n

Nate

04/16/2023, 4:21 PM
I don't believe you can do this from the CLI, but with
run_deployment
you just pass a
flow_run_name
run_deployment(name='hello-prefect/first-deployment-name', flow_run_name="custom-flowrun-name")