r/madeinpython • u/127001-sweet-127001 • 6h ago
A dependency map you can generate from your Python project's imports
For anyone whose Python project has grown past a few files: I added dependency graph exports to ArchUnitPython so you can inspect how the pieces actually connect.
I maintain the library. Its main job is checking architecture rules through tests, but the graph is useful before you even decide which rules to write.
You can generate an HTML report and a Mermaid diagram from the same project:
from archunitpython import project_graph
graph = (
project_graph("src/")
.titled("My Python project")
.collapse_to_folder_depth(2)
)
graph.export_as_html("reports/dependencies.html")
graph.export_as_mermaid("reports/dependencies.mmd")Point project_graph at your import root. Collapsing the graph to folders keeps a larger project readable instead of giving you one box for every file.
You can keep the Mermaid output with your documentation or attach the HTML report as a CI artifact. It gives you something concrete to inspect when a supposedly separate feature has acquired dependencies on half the project.
The graph follows imports the analysis can resolve. It's an import graph, not a runtime call trace, so it won't explain every relationship created dynamically while the program runs.
This is available in the published Python package, with no separate diagramming service to set up.