<@ULVA73B9P> How do I add an optional parameter to...
# ask-marvin
k
@Marvin How do I add an optional parameter to my flow? The type is a list of dictionaries, for example: [{'CFG_ID': 1, 'CFG': {'job_id': 12, 'job_params': {'test': 5}}}, {'CFG_ID': 2, 'CFG': {'job_id': 13, 'job_params': {'test2': 3}}}]
m
To add an optional parameter to your flow in Prefect 3.x, you can use Python's standard function argument syntax. Since you're interested in a parameter that is a list of dictionaries, you can define it with a type hint and a default value. Here's a concise example:
Copy code
python
from prefect import flow

@flow
def my_flow(configs: list[dict] = None):
    if configs is None:
        configs = [{'CFG_ID': 1, 'CFG': {'job_id': 12, 'job_params': {'test': 5}}}]
    # Your flow logic here
    print(configs)

# Example of running the flow
my_flow()
In this example, the
configs
parameter is optional, and if not provided, it defaults to a pre-defined list of dictionaries. Prefect automatically handles type conversion using type hints, so your list of dictionaries will be correctly interpreted. For more details, you might find these resources useful: - Writing Flows in Prefect 3.x - Prefect GitHub Repository Let me know if you have any further questions or need clarification!