Santiago Gutierrez
12/04/2025, 4:49 AMMarvin
12/04/2025, 4:49 AMMarvin
12/04/2025, 4:54 AMprefect run command. To run a flow locally (not deployed) with parameters from the command line, call your flow from a Python entrypoint that parses CLI args and passes them to the flow.
Here’s a simple, reliable pattern:
# my_flow.py
from prefect import flow
@flow
def my_flow(name: str, count: int = 1):
print(f"Hello {name}, running {count} times")
if __name__ == "__main__":
import argparse, json
parser = argparse.ArgumentParser()
# Option 1: individual flags
parser.add_argument("--name")
parser.add_argument("--count", type=int)
# Option 2: a JSON dict for complex params
parser.add_argument("--params", help="JSON dict of flow parameters", default=None)
args = parser.parse_args()
params = {}
if args.params:
params.update(json.loads(args.params))
if args.name is not None:
params["name"] = args.name
if args.count is not None:
params["count"] = args.count
my_flow(**params)
Examples:
- Individual flags:
python my_flow.py --name "Alice" --count 5
- JSON params (handy for nested structures):
python my_flow.py --params '{"name": "Alice", "count": 5}'
Notes for self-hosted:
- This executes in your local Python process. If your environment points to your self-hosted API (e.g., export PREFECT_API_URL=http://<your-server>:4200/api or via a Prefect profile), the run and logs will appear in your UI even though it’s not a deployment.
- There is no direct CLI to run a flow with params without a deployment in 3.x. prefect flow serve creates a runner-style deployment (not an immediate run). If you do want to use a deployment, you can trigger it with parameters via:
prefect deployment run "<FLOW_NAME>/<DEPLOYMENT_NAME>" --param name="Alice" --param count=5
If you want, share your entrypoint/param shapes and I can sketch the exact CLI wrapper for your flow.