If I wanted to parameterize a flow, how would I do...
# prefect-community
If I wanted to parameterize a flow, how would I do that? I'd like to pass an array of strings (email addresses). The flow below works, but I'm not sure it is the proper way to do things. Please ignore the class name, just trying to test.
Copy code
from pydantic import BaseModel

class CustomList(BaseModel):
    data: list[str]

@flow(name = "Fidelity Allocations")
def FidelityAllocationsFlow(toEmail: CustomList):

if __name__ == "__main__":
    emailAddress = CustomList(data=['<mailto:cgunderson@spiderrockadvisors.com|cgunderson@spiderrockadvisors.com>'])
Generally speaking Parameters in 2.0 are determined from the Parameters you set on the flow function, i.e. you shouldn't need to do anything additional beyond writing the python function for the flow parameters to be recognized by the API. this guide covers the basics https://discourse.prefect.io/t/guide-to-implementing-parameters-between-prefect-1-0-and-2-0/1321
@Mason Menges, Thanks. I was looking at this already. Would it be wise to create blocks for a list of email addresses and load that block in the flow instead of using a parameter?
Is this list of emails going to change? Blocks are meant more for storing configurations that relate to external systems, technically it's possible though you could store its as a json block or create a custom one if you wanted to.
It is possible that the list of emails will change if an employee starts/leaves. I just wasn't sure which makes more sense.
The short answer is that you definitely can, but you could also just set the list as a default parameter on the flow
Copy code
from prefect import flow
from typing import List

def test_flow(custom_list: List = ["somedefaultemails"]):
If that makes sense
You should be able to see this parameter in the UI once it's deployed and you can still do runs with custom parameters through there as well
👍 1
Thanks. The next step I have is to write the deployment/schedule scripts