Hey, I’m in the process of switching to Prefect 2....
# prefect-community
Hey, I’m in the process of switching to Prefect 2.x. I’m trying to figure out how to map over multiple arguments and generate child subflows. I realize that
can do something similar to generate tasks, but I’d prefer subflows for my project. Is this possible? If so, any docs or resources y’all can point me to? Thanks!
I’m aware of this link. Perhaps I’m misunderstanding subflows. Regardless, any help would be appreciated. https://docs.prefect.io/faq/#does-prefect-2-support-mapping
Can you show us what you have so far? The subflows can be simply another flow that you call within parent flow. You can call it like you would normally call another Python function. It just needs the
👍 2
so i understand how to generate a single subflow. but is there an equivalent
method that generates multiple subflows?
So, I’ve not used Prefect before 2.5 … I simply create methods and any method that has tasks that I need to call in another flow must also be a flow. Anything that doesn’t need to be a flow or is a small chunk… it is a task. So for me some of the work at the beginning of my flow were tasks … then I would usually have some sort of subflow or two as the next steps, and usually a couple of tasks before returning my final result if I need it stored.
I hope that helps…
Maybe one bit that might be helpful… the bits in a for loop body are usually subflows as they likely will need to call some tasks. Maybe that’s what you’re looking for with the “generate multiple subflows”?
fyi i modified one of the prefect tutorials and it looks like a simple
loop does the job
🎉 1
Copy code
import requests
from prefect import flow

def call_api(url):
    response = requests.get(url)
    return response.json()

def api_flow(url_list: list[str]) -> list[dict]:
    for url in url_list:
        fact_json = call_api(url)
    return fact_json

url_list = [

json_list = api_flow(url_list)

John, I hope that fully solves your issue!