modulegraph
Python module dependency analysis tool
What it is and what it does
modulegraph is a Python module dependency analyzer that uses bytecode examination and AST parsing to determine which modules import which others, producing a directed graph of dependencies. It extends the standard library's modulefinder with more flexible internal representation, better handling of edge cases (namespace packages, invalid modules, relative imports), and extensibility for custom analysis.
The package is primarily used as a building block in tools that need to understand Python module structure—most notably py2app for creating standalone macOS applications. It handles modern Python versions through 3.14 and maintains backward compatibility with Python 2.7, though recent releases focus on contemporary Python support.
Use it for:
- Build tools that need to trace which modules a Python script depends on to bundle or freeze applications.
- Static analysis tools that visualize or report on module dependency graphs within a codebase.
- Linters or auditors checking for circular imports or unintended cross-module dependencies.
- Packaging tools determining which modules to include when distributing a Python application.
- Development environments generating module dependency documentation or diagrams.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
modulegraph analyzes Python module dependencies by examining bytecode and import statements, building a directed graph of which modules depend on which others.
Yes, if you need module dependency analysis for build automation or static analysis. The low install friction, permissive license, and lack of known vulnerabilities make it safe to add. However, the aging maintenance status (265 days since last release) and focus on legacy py2app use suggest it is stable but not actively evolving; verify it meets your specific Python version and analysis requirements before relying on it for new tooling.
Install
modulegraph on PyPI
pip
pip install modulegraphuv
uv add modulegraphpoetry
poetry add modulegraphInstalling modulegraph
Before you install
Low friction installation with only two runtime dependencies (altgraph and setuptools). Maintenance status is aging—last release 265 days ago—but the repository remains active with recent commits and no archived status.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects with minimal obligations.
Quickstart
pip install modulegraph
from modulegraph.modulegraph import ModuleGraph
mg = ModuleGraph()
mg.import_hook('mymodule')
print(mg.nodes())
Verify before relying
- Whether Python 2.7 support is actively maintained or deprecated in practice despite classifier presence.
- Current state of Python 3.13 and 3.14 support maturity given recent addition in 0.19.7.
- Whether the package is suitable for production use in modern Python tooling or primarily maintained for legacy py2app compatibility.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — altgraph, setuptools |
| Maintenance | aging — 265 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 114,882/month — #12,276 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: modulegraph-0.19.7-py2.py3-none-any.whl
Keywords: import, dependencies
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
altgraphaltgraph constructs and analyzes graphs…
permissive · top 5,000 on PyPI
grimpGrimp builds a queryable graph of Python…
permissive · top 5,000 on PyPI
modulegraph2Modulegraph2 builds and introspects a…
permissive · top 15,000 on PyPI
pydepsVisualizes Python module dependencies as graphs…
permissive · top 15,000 on PyPI
pyan3Pyan3 performs static analysis on Python source…
copyleft · top 15,000 on PyPI
objgraphObjgraph lets you visualize and explore Python…
permissive · top 5,000 on PyPI
trailmarkParses source code into a queryable graph of…
permissive · top 15,000 on PyPI
objectgraphObjectgraph provides a Python class for…
permissive · top 15,000 on PyPI
depyfDecompile and inspect the internal bytecode and…
permissive · top 5,000 on PyPI
import-depsAnalyzes Python module imports statically using…
permissive · top 5,000 on PyPI