skillfed

modulegraph

Python module dependency analysis tool

modulegraph v0.19.7 114.9K downloads/30d#12,276 on PyPI45
Permissive license MIT AGING released

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 modulegraph

uv

uv add modulegraph

poetry

poetry add modulegraph

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Build ToolsTopic :: Software Development :: Libraries :: Python Modules

Tags

python module dependency analysisimport graph analysisbytecode import scanningmodule dependency visualizationpython import tracingstatic module analysisdependency graph builder
dependency-analysisbytecode-inspectiongraph-building

More Python Modules packages