<@ULVA73B9P> can I create in the same flow multipl...
# ask-marvin
b
@Marvin can I create in the same flow multiples subflows?
m
Yes, in Prefect 3.x, you can create multiple subflows within a single flow. Subflows are essentially flows that are called within another flow, allowing you to modularize and organize your workflows. The
flow
decorator is used to define both main flows and subflows. Here's a simplified example of how you might structure multiple subflows within a main flow:
Copy code
python
from prefect import flow

@flow
def subflow_one():
    print("Running subflow one")

@flow
def subflow_two():
    print("Running subflow two")

@flow
def main_flow():
    subflow_one()
    subflow_two()

if __name__ == "__main__":
    main_flow()
This structure allows you to execute
subflow_one
and
subflow_two
as part of the
main_flow
. Each subflow can be independently defined and executed, providing flexibility in organizing your tasks. For more details, you can explore the Prefect documentation on flows and subflows.
b
@Marvin can I call the same subflow multiple times in prefect 2?
m
Yes, in Prefect 2.x, you can call the same subflow multiple times within a main flow. Subflows are essentially flows that can be invoked within another flow, allowing you to modularize your workflows and reuse them as needed. Here's a simplified example of how you might call the same subflow multiple times:
Copy code
python
from prefect import flow

@flow
def subflow():
    print("Running subflow")

@flow
def main_flow():
    subflow()  # First call
    subflow()  # Second call

if __name__ == "__main__":
    main_flow()
In this example, the
subflow
is called twice within the
main_flow
. Each call to the subflow will execute it as a separate flow run. For more details, you can explore the Prefect 2.x documentation on flows and subflows.