Team, Can someone share an example (Prefect 2.0) t...
# prefect-community
x
Team, Can someone share an example (Prefect 2.0) to have a flow with kwargs and pass parameter in the DeploymentSpec for the flow? So that I can pass many parameters dynamically. Thank you for your help.
a
Something like https://orion-docs.prefect.io/concepts/deployments/#multiple-deployments-for-a-flow maybe?
Copy code
# filename: hello_flow.py
from prefect import flow

@flow
def hello_world(name="world"):
    print(f"Hello {name}!")
Copy code
from prefect.deployments import Deployment
from prefect.deployments import FlowScript

Deployment(
    flow=FlowScript(path="/path/to/hello_flow.py", name="hello_world"),
    name="Hello World-daily",
    schedule=IntervalSchedule(interval=timedelta(days=1)),
    parameters={"name": "Arthur"},
    tags=["arthur","daily"],
)
🙌 1
🙏 1
x
Thanks Andrew. Actually I may not know how many parameters I pass in that flow. It can be name or fname and lname or name and dob, etc. The flow should take the parameters I pass in DeploySpec as kwargs and use it inside my flow.
a
Copy code
# filename: hello_flow.py
from prefect import flow

@flow
def hello_world(generic_kwargs=None):
    generic_kwargs = generic_kwargs or {}
    print("got {len(generic_kwargs)} kwargs!")

hello_world(generic_kwargs=dict(fname="fname", lname="lname"))
something like this?
x
got it. Thanks, Andrew.