Skip to main content

Understand your Python dependencies. Find cycles, dead modules, and architecture problems.

Project description

DependaMan

Understand your Python project's internal structure. Find cycles, dead modules, hotspots, and architecture problems — visualized as an interactive graph.

No external Python dependencies. Pure stdlib only.


Goal

Given a Python project directory, DependaMan produces an interactive HTML graph showing:

  • Which modules import which (directed dependency graph)
  • Which modules are never imported (dead code candidates)
  • Circular import chains
  • Modules with high fan-in (many dependents) or high fan-out (many dependencies)
  • Module size (lines of code, number of functions/classes)
  • Git churn: how often each module changes

Architecture

Phase 1 — File Discovery

Walk the project directory, collect all .py files, and determine the package root. Distinguish internal modules from external ones (stdlib + third-party are ignored).

Phase 2 — Import Parsing

Use ast to parse each file and extract import and from ... import statements. Resolve relative imports. Filter to internal-only imports.

Phase 3 — Graph Construction

Build a directed graph as an adjacency structure:

  • Node = internal module
  • Edge A → B = "module A imports module B"

Attach metadata to each node: file path, line count, function/class count.

Phase 4 — Analysis

Run these passes on the graph:

  • Dead code: nodes with no incoming edges and not an entry point
  • Circular imports: detect cycles (DFS-based)
  • Hotspots: nodes ranked by fan-in (most imported)
  • Coupling: nodes ranked by fan-out (imports the most)

Phase 5 — Git Integration

Use subprocess + git log to compute per-file:

  • Commit frequency (how often it changes)
  • Lines added/removed over time (churn)
  • Last author that changed the file

Attach this data to graph nodes. Optional: skipped if the project is not a git repo.

Phase 6 — HTML Output

Generate a self-contained .html file (or return HTML as a string for web integration).

The HTML template is a static string embedded in Python. Only the data changes between runs. Python serializes the graph to JSON and injects it into the template — no templating library needed:

import json

data = json.dumps({"nodes": [...], "edges": [...]})
html = TEMPLATE.replace("__GRAPH_DATA__", data)

The template contains a <script> block that reads the injected data and renders the graph using the browser's <canvas> or SVG API. No external JS libraries required.

The graph supports:

  • Hover tooltips: quick summary (import count, churn score)
  • Click modals: full detail panel (git log, list of dependents/dependencies, size metrics)

The output function signature is designed to be framework-agnostic:

def render(graph, analysis) -> str:  # returns HTML string
    ...

This makes it trivial to plug into FastAPI, Flask, or any other framework:

# FastAPI example
@app.get("/graph", response_class=HTMLResponse)
def dependency_graph():
    graph = build_graph(".")
    analysis = analyze(graph)
    return render(graph, analysis)

Package Structure

DependaMan is distributed as a Python package (dependaman). The current layout:

dependaman/
    __init__.py        # public API: dependaman()
    __main__.py        # CLI entry point
    core.py            # orchestration
    discovery.py       # Phase 1 — file discovery
    parser.py          # Phase 2 — import parsing
    graph.py           # Phase 3 — graph construction
    analysis.py        # Phase 4 — analysis passes
    git.py             # Phase 5 — git integration
    renderer.py        # Phase 6 — HTML output
    pool.py            # GIL-aware executor selection

Entry point via pyproject.toml:

[project.scripts]
dependaman = "dependaman.__main__:dependaman"

Usage

CLI:

dependaman              # analyzes current directory, opens browser
dependaman /path/to/project

Python API:

from dependaman import dependaman

html = dependaman(".", in_memory=True)   # returns HTML string
dependaman(".")                          # writes output.html + opens browser

Roadmap

  • Phase 1: File discovery
  • Phase 2: Import parsing (ast)
  • Phase 3: Graph construction
  • Phase 4: Analysis (dead code, cycles, hotspots)
  • Phase 5: Git integration
  • Phase 6: HTML renderer
  • Phase 7: Unused symbol detection (functions, classes, methods never imported)
  • Phase 8: Installable package (uv pip install -e .)
  • Phase 9: CLI entry point with auto project root detection and browser open
  • Phase 10: Performance — parallel git stats (ThreadPoolExecutor), GIL-aware pool for parsing and graph construction

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dependaman-1.0.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dependaman-1.0.1-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file dependaman-1.0.1.tar.gz.

File metadata

  • Download URL: dependaman-1.0.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dependaman-1.0.1.tar.gz
Algorithm Hash digest
SHA256 bee52a69929f21711a126652b4824bae21eabd197c27de22f2012206b31297ef
MD5 bc366e5addf3c030682d8c7264d2d869
BLAKE2b-256 06f24ee729a3724873983684b5df076a87a27d13a73c8ae32a7e38f5bbf71efe

See more details on using hashes here.

File details

Details for the file dependaman-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: dependaman-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dependaman-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a45dafd1fcd811ce166e0651ef40a97c4b23fe879994094d75999598a429b5b0
MD5 b31cb96d6335162d97c28a9bbd10cb63
BLAKE2b-256 6292c24a8422255b31757c9373c363a6e714e4bee254af0baf544818d96edce1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page