modulegraph2
A module import dependency graph for Python projects.
What it is and what it does
Modulegraph2 is a library for building and analyzing the dependency graph between Python modules. It performs static analysis on both source code and bytecode to discover which modules import which others, and annotates each dependency with metadata from the import statement itself. The graph also includes information about packages, extensions, and their relationships, with links to distribution metadata for modules installed via pip.
The package is a complete rewrite of an earlier modulegraph project, built from scratch for Python 3 with full test coverage. It's useful for understanding module structure, detecting circular dependencies, or building tools that need to reason about import relationships in a codebase.
Use it for:
- Analyze import dependencies in a Python project to detect circular imports or unused modules.
- Build tooling that needs to understand the module structure of a codebase for refactoring or optimization.
- Generate documentation or visualizations of how modules in a project depend on each other.
- Validate that a package's public API only imports from intended modules.
- Trace which installed distributions provide modules used by a given Python project.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Modulegraph2 builds and introspects a dependency graph of Python modules using static analysis of source and bytecode, annotating imports with metadata and linking to installed package information.
Yes, if you need to programmatically analyze Python module dependencies. The package is stable, has no known vulnerabilities, installs easily, and supports current Python versions. The aging maintenance status (264 days since last release) is a minor concern for a mature library, but not a blocker unless you need active development or rapid bug fixes.
Install
modulegraph2 on PyPI
pip
pip install modulegraph2uv
uv add modulegraph2poetry
poetry add modulegraph2Installing modulegraph2
Before you install
Low friction installation with a pure-wheel distribution. Maintenance is aging—last release was 264 days ago and the repository shows infrequent recent activity—but the package is marked Production/Stable and supports current Python versions through 3.15.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install modulegraph2
from modulegraph2 import ModuleGraph
graph = ModuleGraph()
graph.add_module('mypackage')
for node in graph.nodes():
print(node)
Requires Python 3.10 or later.
Verify before relying
- Whether the static analysis accurately handles dynamic imports, conditional imports, or complex import patterns in real-world codebases.
- Performance characteristics when analyzing large projects with hundreds or thousands of modules.
- Whether the rewrite from the original modulegraph maintains backward compatibility or introduces breaking changes for existing users.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — typing_extensions, objectgraph |
| Maintenance | aging — 264 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 129,321/month — #11,674 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: modulegraph2-2.3-py3-none-any.whl
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
modulegraphmodulegraph analyzes Python module dependencies…
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
graphlibProvides a Python API for creating,…
permissive · top 15,000 on PyPI
pydepsVisualizes Python module dependencies as graphs…
permissive · top 15,000 on PyPI
altgraphaltgraph constructs and analyzes graphs…
permissive · top 5,000 on PyPI
import-linterImport Linter enforces architectural…
permissive · top 5,000 on PyPI
grimpGrimp builds a queryable graph of Python…
permissive · top 5,000 on PyPI
funcsigsProvides Python function signature…
permissive · top 5,000 on PyPI
graphiti-coreGraphiti builds and queries temporal context…
permissive · top 5,000 on PyPI