<@ULVA73B9P> If I am deploying a workflow with the...
# ask-marvin
s
@Marvin If I am deploying a workflow with the .serve method, can I pass parameters to that workflow? If so please give an example.
m
Yes, you can pass parameters to a workflow when using the
.serve
method in Prefect 3.x. The
serve
method is a long-running process that allows you to execute remotely triggered or scheduled runs, and you can serve multiple flows using this utility. Here's an example of how you might define and serve a flow with parameters:
Copy code
python
from prefect import flow, serve

@flow
def my_flow(param1: int, param2: str):
    print(f"Running with param1: {param1} and param2: {param2}")

if __name__ == "__main__":
    # Serve the flow, which allows it to accept parameters when triggered
    serve(my_flow)
When you trigger this flow through the Prefect UI or API, you can specify the parameters
param1
and
param2
to customize the execution. For more details, you can refer to the Prefect documentation on running flows in local processes.
n
plus1 you can also set default params with
parameters: dict
on serve
s
Thanks!