Thread
#prefect-community
    a

    Andy

    1 year ago
    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?
    Samuel Hinton

    Samuel Hinton

    1 year ago
    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!
    Dylan

    Dylan

    1 year ago
    You can also use the CLI that ships with Prefect Core:
    (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

    1 year ago
    Both of these methods work. Thank you 🙂