https://prefect.io logo
#prefect-community
Title
# prefect-community
x

Xavier Babu

07/21/2022, 9:47 PM
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

Andrew Huang

07/21/2022, 9:59 PM
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

Xavier Babu

07/21/2022, 10:34 PM
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

Andrew Huang

07/21/2022, 11:26 PM
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

Xavier Babu

07/22/2022, 8:27 PM
got it. Thanks, Andrew.
4 Views