Hey Prefect Community,
I'm brand new at prefect and have been trying to figure out how to run a flow with an API call. Is that possible for a locally hosted project?
Example:
Copy code
POST - http://{LocalHost}/api/flow_runs
BODY
{
"flow_id": "2c1e5ce1-38ef-4a65-a762-ebb14630920d"
}
This correctly creates a flow run, but it remains in pending state and never actually runs.
n
Nate
01/25/2025, 12:20 AM
hey @Adam Holderness! welcome
you'll want
POST /create_flow_run_from_deployment
Nate
01/25/2025, 12:21 AM
otherwise (as you've noticed) you're more or less just creating a flow run record, but not putting it into a (
Scheduled
) state that your worker (client side poller) cares about / notices
Nate
01/25/2025, 12:23 AM
fwiw you can use
run_deployment
to do this easily if you find yourself using the SDK, @Marvin short example of this pls
m
Marvin
01/25/2025, 12:23 AM
To use
run_deployment
in Prefect 3.x, you can follow this simple example. This assumes you are using the Prefect SDK to trigger a deployment programmatically.
Here's a basic example of how you might use `run_deployment`:
Copy code
python
from prefect.deployments import run_deployment
# Run a deployment by specifying the deployment name and flow name
deployment_run = run_deployment(
deployment_name="my-deployment",
flow_name="my-flow"
)
# You can access the deployment run's ID or other metadata if needed
print(deployment_run.id)
This snippet will trigger a deployment that you've previously created in your Prefect Cloud or Prefect Server setup. You'll need to replace
"my-deployment"
and
"my-flow"
with your actual deployment and flow names.
For more details on using deployments in Prefect, you can refer to the Prefect Deploy documentation.
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.