v2.3.1 — The Ground Truth Engine

LLMs guess your architecture. py-code-visualizer proves it.

A deterministic, AST-verified call graph for any Python project — every edge traceable to a file:line. The reproducible, CI-gateable alternative to LLM-generated diagrams. No code executed. Nothing leaves your machine.

pip install py-code-visualizer
Python 3.8-3.12 Supported Versions
100% Safe AST-based, No Execution
MIT License Open Source
Features

Everything You Need to Understand Your Code

From quick analysis to deep architectural insights, PyVisualizer has you covered.

AST-Based Analysis

Pure static analysis using Python's Abstract Syntax Tree. No code execution, completely safe for any codebase.

Function Call Graphs

Track function and method calls across modules. See exactly how your code connects and flows.

Interactive D3.js Visualizations

Force-directed graphs with search, filter, zoom, pan, and dark mode. All in a single HTML file.

Mermaid Diagrams

Generate diagrams that render natively in GitHub, GitLab, VS Code, and any Mermaid viewer.

Flexible Filtering

Focus on specific modules, exclude tests, limit call depth, and control graph size for large codebases.

CI/CD Ready

Auto-update diagrams on every push with included GitHub Actions workflows.

Demo

See It in Action

Interactive Mermaid diagram of PyVisualizer's architecture — just like what you'll generate!

architecture.mmd — PyVisualizer Call Graph
flowchart TD
    subgraph CLI["CLI Layer"]
        main["main()"]
        parse["parse_args()"]
    end
    
    subgraph Core["⚙️ Core Analysis"]
        analyze["analyze_project()"]
        discover["discover_files()"]
        ModuleAnalyzer["ModuleAnalyzer"]
        ImportCollector["ImportCollector"]
    end
    
    subgraph Graph["Graph Building"]
        build["build_call_graph()"]
        GraphBuilder["GraphBuilder"]
        resolve["resolve_calls()"]
    end
    
    subgraph Visualizers["Visualizers"]
        d3["generate_d3_html()"]
        mermaid["generate_mermaid()"]
        svg["generate_svg()"]
    end
    
    subgraph Output["Output"]
        html["architecture.html"]
        mmd["architecture.mmd"]
        image["architecture.svg/png"]
    end
    
    main --> parse
    main --> analyze
    analyze --> discover
    analyze --> ModuleAnalyzer
    ModuleAnalyzer --> ImportCollector
    analyze --> build
    build --> GraphBuilder
    GraphBuilder --> resolve
    build --> d3
    build --> mermaid
    build --> svg
    d3 --> html
    mermaid --> mmd
    svg --> image

    style CLI fill:#0C3E2F,stroke:#0C3E2F,color:#fff
    style Core fill:#14624A,stroke:#0C3E2F,color:#fff
    style Graph fill:#1C8462,stroke:#14624A,color:#fff
    style Visualizers fill:#275E6E,stroke:#1B4351,color:#fff
    style Output fill:#3B8095,stroke:#275E6E,color:#fff
                    
Zoom with mouse wheel
Pan by dragging
Renders on GitHub
Quick Start

Up and Running in Seconds

Install from PyPI and generate your first diagram

1

Install

pip install py-code-visualizer
2

Generate Interactive HTML

py-code-visualizer visualize . -o architecture.html
3

Or Self-Heal Your README

py-code-visualizer readme .

CLI Options

--format, -f html, mermaid, svg, png
--modules, -m Filter to specific modules
--exclude, -x Exclude patterns (e.g., tests)
--entry, -e Entry point function
--depth, -d Max call depth from entry
--max-nodes Limit graph size (default: 150)
Why PyVisualizer?

The Right Tool for the Job

See how PyVisualizer compares to other Python visualization tools

Feature PyVisualizer Pydeps Pyreverse
Primary Focus Function Call Graphs Module Dependencies UML Class Diagrams
Interactive Visualization ✓ D3.js with search, filter, zoom ✗ Static images only ✗ Static images only
GitHub-Native Diagrams ✓ Mermaid support ✓ Mermaid support
Function-Level Detail ✓ (Classes only)
Dark Mode
CI/CD Integration ✓ Included workflows Manual setup Manual setup
Output Formats HTML, Mermaid, SVG, PNG SVG, PNG DOT, PNG, SVG, PlantUML

When to use which?

PyVisualizer: Understanding function flow, interactive exploration, onboarding engineers

Pydeps: High-level module dependency mapping

Pyreverse: UML documentation, class inheritance visualization

Use cases

Two jobs, one engine

This tool exists to make code review faster and to give AI agents verified context. Every walkthrough is backed by a runnable fixture — nothing staged.

Built for your stack

Whatever kind of Python you write

Backend, API, or ML — the call graph is the same ground truth, shaped to how your project is actually laid out.

Proof, not promises

The numbers are measured, not marketed

Every figure below comes from a committed benchmark script you can re-run. No hand-typed metrics.

~4.9 s
to map a 98,669-line project (26,658 functions, 1,399 files)
100%
of call edges carry a file:line — provenance on every arrow
0
network requests in the generated HTML — air-gap safe by construction
SHA-256
equal
two runs, byte-identical output — diffable, gate-able, committable
97%
fewer tokens for AI agents — 139,697 → ~4,000 on a real open-source codebase
$2.04
saved per task on Claude Opus 5 — 35× more relevant-code signal per token vs full source

Token measurements ran on the httpx codebase (1,076 functions, real closed bug) using py-code-visualizer context --task. Speed benchmark: macOS (arm64), Python 3.14, commit 79c3900, on a deterministic synthetic project (seed 1998). Speed is hardware-dependent — reproduce it yourself with python benchmarks/bench.py, which writes benchmarks.json. Provenance, zero-network, and byte-determinism are structural guarantees, not benchmark luck.

For AI Agents & LLMs

Point your agent at the graph, not the repo

Deterministic ground truth an LLM can trust — served openly, no cloaking, no bait.

AI coding agents (Cursor, Claude, Copilot, and autonomous RAG crawlers) re-derive a project's architecture from raw source and routinely hallucinate the result. py-code-visualizer gives them a verified alternative:

  • py-code-visualizer export --for-ai . emits ARCHITECTURE.json + ARCHITECTURE.md — a call graph with file:line provenance on every edge.
  • Every relationship is parsed from the AST, never inferred; ambiguous calls are flagged, not guessed.
  • Output is deterministic, so the facts an agent reads today match the facts it reads tomorrow.
FAQ

Frequently asked questions

How do I visualize a Python project's architecture?
Install with pip install py-code-visualizer and run py-code-visualizer visualize . to generate a self-contained interactive HTML map of your project's call graph. It uses AST static analysis, so no code is executed.
How is this different from an LLM-generated architecture diagram?
py-code-visualizer parses the actual AST, so every call-graph edge is real and traceable to a specific file and line. Its output is deterministic (byte-identical across runs), so it can be diffed and gated in CI. LLM-generated diagrams are inferred, frequently hallucinate relationships, and are non-reproducible.
Does py-code-visualizer execute my code?
No. It performs pure static analysis with Python's ast module. Nothing is imported or executed, and the interactive HTML output makes zero network requests, so it is safe for any codebase and works air-gapped.
Can it keep an architecture diagram in my README up to date automatically?
Yes. py-code-visualizer readme injects or updates a Mermaid diagram between marker comments in any Markdown file. Because output is deterministic, a CI job only commits when the architecture actually changed — no phantom diffs.
Can it fail CI when a circular dependency is introduced?
Yes. py-code-visualizer check --fail-on-cycles exits non-zero on circular dependencies, and layering rules declared in pyproject.toml are enforced at call-graph level. py-code-visualizer diff reports newly introduced cycles between two snapshots.
How do I map an undocumented Python monolith?
py-code-visualizer visualize <project> -o map.html for an interactive map, health for an A–F grade, and check --dead-code for a list of unreachable functions — no code executed, every edge traceable to a file:line. Full walkthrough: the orphan monolith.
How do I produce architecture evidence for a SOC 2 audit?
Enforce layer rules at call-graph level — check --layers api domain infra --forbid 'domain -> api' — and the gate fails CI with the exact file:line. Deterministic committed diagrams make git history a dated audit trail, and the single-file HTML makes zero network requests (air-gap safe). Full walkthrough: the audit deadline.
How do I find the blast radius of a Python refactor?
py-code-visualizer impact <function> <project> reports transitive callers/callees and the modules they span. Snapshot the graph before and after and run diff base.json head.json --fail-on-new-cycles to fail a PR that introduces a cycle. Full walkthrough: the fearless refactor.
How do I review a large Python pull request faster?
py-code-visualizer review . --base origin/main turns the diff into a focused map — changed functions, blast radius, risk flags (hubs, new cycles, ambiguous calls), and a changed-neighborhood diagram — with a clickable file:line on every reference. init --with review posts it as a PR comment automatically. Full walkthrough: review a PR in minutes.
How do I give an AI coding agent verified context about my codebase?
py-code-visualizer context . --focus <fn> builds a task-scoped pack (97% fewer tokens than the whole source on a real project, zero guessed edges), and export --for-ai wires AGENTS.md so Copilot/Cursor/Claude consume the verified graph. Full walkthrough: feed your agent the right context.

Ready to Visualize Your Code?

Get started in seconds with a single command

pip install py-code-visualizer