https://prefect.io logo
a

Andy

02/22/2021, 2:48 PM
Is there a way to run a specific registered flow from Python instead clicking the run button in the Prefect UI? e.g. is there a way to do something like
flow = load('{project_name}.{flow})
and
flow.run()
which would then show up in the Prefect UI?
s

Samuel Hinton

02/22/2021, 2:49 PM
Copy code
from prefect.client import Client
client = Client("<http://localhost:4200/graphql>")
client.create_flow_run(flow_id)
is what you want. If you register a flow, you get the id back, so you can register and run using the API. I dont know of a good way of saying “whats the latest id for a flow with this name” so if you figure that out please let me know!
d

Dylan

02/22/2021, 3:06 PM
You can also use the CLI that ships with Prefect Core:
Copy code
(prefect) dylanhughes@Dylans-MacBook-Pro-Prefect ~> prefect run
Usage: prefect run [OPTIONS] COMMAND [ARGS]...

  Run Prefect flows.

  Usage:
      $ prefect run [STORAGE/PLATFORM]

  Arguments:
      flow    Run a flow with a backend API

  Examples:
      $ prefect run flow --name Test-Flow --project My-Project -ps '{"my_param": 42}'
      Flow Run: <https://cloud.prefect.io/myslug/flow-run/2ba3rrfd-411c-4d99-bb2a-f64a6dea78f9>

      $ prefect run flow --name Test-Flow --project My-Project --watch
      Flow Run: <https://localhost:8080/flow-run/2ba3rrfd-411c-4d99-bb2a-f64a6dea78f9>
      Scheduled -> Submitted -> Running -> Success

Options:
  -h, --help  Show this message and exit.
a

Andy

02/22/2021, 3:11 PM
Both of these methods work. Thank you 🙂