<@ULVA73B9P> if I import a flow, is there any way ...
# ask-marvin
k
@Marvin if I import a flow, is there any way to inspect the topology? What tasks are called, what the dependencies are, etc?
m
thought for 121.0 seconds
Short answer: not statically. In Prefect 3.x the task graph is built dynamically as your flow runs, so there isn’t a compile-time API to list “all tasks and dependencies” without executing the flow code at least once. What you can do: - Programmatic graph from a run - Prefect tracks task calls and their upstream dependencies during execution. You can extract a Graphviz DOT graph (and render it) from the current run:
Copy code
from prefect.visualization import get_task_viz_tracker, build_task_dependencies

  # Call this near the end of your flow or right after running it locally
  tvt = get_task_viz_tracker()
  if tvt:
      graph = build_task_dependencies(tvt)  # returns graphviz.Digraph
      print(graph.source)                   # DOT source (nodes/edges)
      # Optional: render to file (requires Graphviz installed)
      graph.render("flow-topology", format="png", cleanup=True)
Notes: -
graph.source
contains a DOT description you can parse if you want nodes/edges programmatically. - Rendering requires Graphviz on your system; if it isn’t present you’ll see an error. - See it in the UI - Run the flow once (locally or via a deployment) and open the run’s details page; you’ll get a visualization of task executions and their dependencies for that run. - Inspect a specific run via CLI - For a given run id:
Copy code
prefect flow-run inspect <RUN_ID>
This shows details about that flow run (states, etc.); it’s not a static DAG preview, but helpful for understanding what ran. Limitations to be aware of: - Because control flow is dynamic (loops, conditionals, mapping), the topology can differ between runs based on parameters and runtime branches. The visualization reflects the actual run, not a static plan. If you’re hoping to inspect the topology without running anything at all, can you share more about your use case? I can suggest a minimal “smoke run” approach or alternatives depending on what you need.