merlin
01/07/2025, 6:24 PM["extract", "create_report", "upload"]
. I don't want to define each subflow as a deployment.Marvin
01/07/2025, 6:24 PMpython
from prefect import flow
# Define your subflows
@flow
def extract():
print("Extracting data...")
@flow
def create_report():
print("Creating report...")
@flow
def upload():
print("Uploading data...")
# Map subflow names to functions
subflows = {
"extract": extract,
"create_report": create_report,
"upload": upload
}
# List of subflow names to execute
subflow_names = ["extract", "create_report", "upload"]
# Execute subflows by name
for name in subflow_names:
subflows[name]()
2. Flow Engine: The Prefect flow engine does have some internal methods like load_subflow_run
and create_flow_run
that interact with subflows. However, these are not typically exposed for direct use without deploying flows.
For more details, you can explore the Prefect flow engine source code.
If you're looking for a more native solution or feature, it might involve contributing a feature request or checking for updates in the Prefect repository.merlin
01/07/2025, 6:28 PMextract()
subflow needs the parameters file_name: str
and datastore_type: str
.Marvin
01/07/2025, 6:28 PMpython
from prefect import flow
# Define your subflows with parameters
@flow
def extract(file_name: str, datastore_type: str):
print(f"Extracting data from {file_name} using {datastore_type} datastore...")
@flow
def create_report():
print("Creating report...")
@flow
def upload():
print("Uploading data...")
# Map subflow names to functions
subflows = {
"extract": extract,
"create_report": create_report,
"upload": upload
}
# List of subflow names to execute with their respective parameters
subflow_params = {
"extract": {"file_name": "data.csv", "datastore_type": "SQL"},
"create_report": {},
"upload": {}
}
# Execute subflows by name with parameters
for name, params in subflow_params.items():
subflows<**params|name>
In this example, the extract
subflow is executed with the parameters file_name
and datastore_type
. Each subflow can have its own set of parameters defined in the subflow_params
dictionary. This approach allows you to flexibly manage and execute various subflows with their specific parameters.merlin
01/07/2025, 6:35 PMMarvin
01/07/2025, 6:35 PM