Interactive dependency graph & blast-radius analyzer for Python projects
Project description
depgraph ๐
Interactive Python dependency graph & blast-radius analyzer
Know exactly what breaks before you refactor.
The Problem
You want to delete a function, rename a class, or split a module โ but you have no idea what else will break. Your IDE shows one level of imports. You need the full picture.
depgraph gives you that picture in seconds:
- ๐ฅ Blast radius โ "if I delete X, these 14 things break"
- ๐ด Circular import detection โ every cycle, with severity scores and fix suggestions
- ๐ป Orphan detection โ dead code that nothing imports
- ๐ Interactive D3.js graph โ zoomable, draggable, folder-clustered, with a click-to-inspect node panel
Zero execution โ purely static analysis via Python's built-in ast module.
Install
pip install depgraph-py
Quick Start
# Scan your project and get a full summary
depgraph scan ./my_project
# Open the interactive graph in your browser
depgraph visualize ./my_project
# Find what breaks if you remove a symbol
depgraph impact ./my_project payments.processor.PaymentProcessor
# Detect all circular imports
depgraph cycles ./my_project
# Find unused modules (dead code candidates)
depgraph orphans ./my_project
# See what a module depends on
depgraph deps ./my_project payments.processor
Using python -m (if the CLI command is blocked)
If your organisation's security policy blocks installed entry points, run every command via python -m depgraph.cli instead โ behaviour is identical:
python -m depgraph.cli scan "D:\my_project"
python -m depgraph.cli visualize "D:\my_project"
python -m depgraph.cli impact "D:\my_project" payments.processor.PaymentProcessor
python -m depgraph.cli cycles "D:\my_project" --strict
python -m depgraph.cli orphans "D:\my_project"
python -m depgraph.cli deps "D:\my_project" smtp
Windows paths with spaces must be quoted: (Example)
python -m depgraph.cli deps "C:\my-project\project" module_name
Commands
depgraph scan <path>
Full project summary โ files, modules, classes, functions, cycle count, orphan count, and a hot-spots table of the most depended-on modules.
โญโ depgraph โ /home/user/my_project โโฎ
โ โ
โ ๐ Python files 42 โ
โ ๐ฆ Modules 38 โ
โ ๐๏ธ Classes 121 โ
โ โ๏ธ Functions 489 โ
โ ๐ Dependencies 734 โ
โ ๐ด Circular imports 2 โ
โ ๐ป Orphan modules 5 โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
๐ฅ Most depended-on modules:
utils.logger โโโโโโโโโโโโโโโโ 16
db.models โโโโโโโโโโโโ 12
core.config โโโโโโโโ 8
depgraph impact <path> <symbol>
Show exactly what depends on a symbol โ directly and transitively. Tells you the full blast radius before you touch anything.
depgraph impact . payments.processor.PaymentProcessor
๐ฅ Blast Radius โ payments.processor.PaymentProcessor
Total impact: 11 nodes affected (22.9% of project)
๐ด Direct dependents (break immediately):
โ api.views.PaymentView
โ tests.test_payments
๐ก Transitive dependents (break indirectly):
โ api.router
โ main
... and 7 more
depgraph cycles <path>
Detect every circular import chain in the project. Each cycle gets a severity rating (CRITICAL / HIGH / MEDIUM / LOW) and a concrete fix suggestion.
depgraph cycles ./my_project
# Exit with code 1 if any cycles found โ useful in CI
depgraph cycles ./my_project --strict
๐ Found 2 circular import(s)
[CRITICAL] Cycle 1 (2 nodes)
auth.service โ db.models โ auth.service
๐ก Extract shared logic into a new common.py module
[HIGH] Cycle 2 (4 nodes)
api.views โ orders.handler โ payments.processor โ api.views
๐ก Use dependency injection or move shared types to interfaces.py
depgraph visualize <path>
Generate a self-contained interactive HTML graph and open it in your browser. No server needed โ it's a single file you can share with your team.
# Full project graph
depgraph visualize ./my_project
# Pre-highlight the blast radius of a symbol
depgraph visualize ./my_project --highlight payments.processor
# Save to a specific path
depgraph visualize ./my_project --output reports/deps.html
# Generate but don't open the browser
depgraph visualize ./my_project --no-open
What you get in the graph:
| Feature | Description |
|---|---|
| Folder cluster bubbles | Dashed coloured hulls group nodes by top-level package |
| Click to inspect | A slide-in panel shows blast radius, stats, file path, and dependency lists |
| Search bar | Header search โ type to filter nodes, โโ to navigate, Enter to jump |
| Folder filter | Click a folder in the sidebar to isolate it |
| View modes | Full Graph / Circular Imports only / Orphan Modules only |
| Zoom & pan | Mouse wheel + drag, or toolbar buttons |
| Blast radius highlight | Orange = direct dependents, gold = transitive |
Node colour coding:
| Colour | Meaning |
|---|---|
| ๐ต Blue | Module (.py file) |
| ๐ฃ Purple | Class |
| ๐ฉต Teal | Function |
| ๐ด Red (glowing) | Part of a circular import cycle |
| ๐ก Yellow | Orphan โ nothing imports this |
| ๐ Orange | Blast radius โ direct dependent of selected node |
depgraph orphans <path>
Find modules, classes, or functions that nothing else imports. These are either dead code or entry points (like main.py or cli.py).
๐ป 5 orphan(s) found (nothing imports them):
๐ป scripts.migrate_data (module) โ scripts/migrate_data.py
๐ป utils.old_helpers (module) โ utils/old_helpers.py
๐ป tests.conftest (module) โ tests/conftest.py
depgraph deps <path> <symbol>
Show what a specific symbol depends on โ its own imports and all transitive dependencies.
depgraph deps . payments.processor
๐ Dependencies of payments.processor
Direct dependencies:
โ utils.logger
โ db.models
Transitive dependencies:
โ core.config
โ core.base
Python API
Use depgraph programmatically in your own scripts or tools:
from pathlib import Path
from depgraph.crawler import crawl_project
from depgraph.parser import parse_project
from depgraph.graph import build_graph
from depgraph.analyzer import Analyzer
from depgraph.visualizer import visualize
root = Path("./my_project")
# 1. Build the graph
py_files = crawl_project(str(root))
modules = parse_project(py_files, root)
graph = build_graph(modules)
# 2. Analyze
analyzer = Analyzer(graph)
# Blast radius of a symbol
result = analyzer.blast_radius("payments.processor.PaymentProcessor")
print(f"Affects {result.total_impact} nodes ({result.impact_percentage}%)")
print("Direct dependents:", result.direct_dependents)
print("Transitive dependents:", result.transitive_dependents)
# Find all circular imports
for cycle in analyzer.find_cycles():
print(f"[{cycle.severity}] {' โ '.join(cycle.nodes)}")
# Find orphaned modules
print("Orphans:", analyzer.find_orphans())
# 3. Generate the interactive HTML graph
html_path = visualize(
graph,
output_path="my_graph.html",
cycles=analyzer.find_cycles(),
orphans=analyzer.find_orphans(),
project_name="my_project",
)
print("Graph saved to:", html_path)
CI/CD Integration
Catch circular imports on every pull request:
# .github/workflows/depgraph.yml
name: Dependency Check
on: [push, pull_request]
jobs:
check-cycles:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install depgraph-py
- name: Check for circular imports
run: depgraph cycles . --strict
How It Works
depgraph does everything through static analysis โ it never runs your code.
Your .py files
โ
AST Parser โ extracts imports, classes, functions
โ resolves relative imports (., .., ...)
NetworkX DiGraph โ directed graph: A โ B means A imports B
โ
Impact Analyzer โ reverse BFS to compute blast radius
Cycle Detector โ Tarjan's SCC algorithm
Orphan Finder โ nodes with zero incoming edges
โ
D3.js HTML Graph โ self-contained interactive visualization
Project Structure
depgraph/
โโโ crawler.py โ walks .py files, skips venv / __pycache__
โโโ parser.py โ AST extraction, resolves relative imports
โโโ graph.py โ builds the NetworkX directed graph
โโโ analyzer.py โ blast radius, cycle detection, orphan finding
โโโ visualizer.py โ generates the D3.js interactive HTML
โโโ cli.py โ Typer CLI (6 commands)
Requirements
- Python 3.8+
networkx >= 3.0โ graph enginetyper >= 0.9.0โ CLI frameworkrich >= 13.0.0โ terminal output
The visualizer uses D3.js 7 via CDN โ no extra Python dependencies needed. A corporate-friendly CDN fallback is included automatically.
Development
git clone https://github.com/Aekkaladevi-Vikas/DepGraph.git
cd depgraph
pip install -e .
pytest tests/ -v
License
MIT โ free for personal and commercial use.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file depgraph_py-0.1.1.tar.gz.
File metadata
- Download URL: depgraph_py-0.1.1.tar.gz
- Upload date:
- Size: 213.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be7893b053955c414e7bb0a278b389761198ef7bef1626f55a0df8309971b951
|
|
| MD5 |
2a36422b05fc94d9992a2425e8f88b75
|
|
| BLAKE2b-256 |
d296bf1a06a3136887b0768a6b990eee03143b0d4e8cb2b7bf9c7588e7407e43
|
File details
Details for the file depgraph_py-0.1.1-py3-none-any.whl.
File metadata
- Download URL: depgraph_py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 30.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d9a66bf6cae76508d270ce947c0262edc12f484bee620cd291d86acb211b97d
|
|
| MD5 |
a802f709ace9826aecbb1a0c8937af69
|
|
| BLAKE2b-256 |
cc0c87656600c53ad055044be40e557c653bbb2186d448e54ec5a10180212bcd
|