Skip to main content

Transform complex Python codebases into beautiful interactive diagrams

Project description

๐ŸŽจ PyVisualizer

CI Python 3.8+ License: MIT

Transform complex Python codebases into stunning, interactive architectural diagrams

PyVisualizer uses static code analysis (AST parsing) to understand your Python code without executing it, then generates beautiful visualizations showing function calls, class relationships, and module dependencies.

PyVisualizer Demo

โœจ Features

๐Ÿ” Intelligent Code Analysis

  • AST-based parsing - No code execution required, completely safe
  • Call graph extraction - Tracks function and method calls across modules
  • Class analysis - Detects inheritance, decorators, properties, and async methods
  • Import resolution - Handles complex import patterns including relative imports

๐ŸŽจ Multiple Visualization Formats

  • Interactive D3.js - Force-directed graphs with zoom, pan, search, and filtering
  • Mermaid Diagrams - Portable diagrams that render in GitHub, GitLab, and VS Code
  • Static Images - SVG and PNG export via Graphviz (optional)

๐Ÿ”ง Flexible Filtering

  • Filter by specific modules
  • Exclude test files or other patterns
  • Limit call depth from entry points
  • Control maximum nodes for large codebases

๐Ÿš€ CI/CD Integration

  • GitHub Actions workflows included
  • Auto-update diagrams on commit
  • PR review with architecture analysis

๐Ÿ“ฆ Installation

pip install py-code-visualizer

Or install from source:

git clone https://github.com/haider1998/PyVisualizer.git
cd PyVisualizer
pip install -e .

For SVG/PNG export (optional):

pip install py-code-visualizer[graphviz]
# Also requires graphviz system package:
# macOS: brew install graphviz
# Ubuntu: sudo apt install graphviz

๐Ÿš€ Quick Start

Basic Usage

# Generate interactive HTML visualization
py-code-visualizer /path/to/your/project --format html -o architecture.html

# Generate Mermaid diagram
py-code-visualizer /path/to/your/project --format mermaid -o architecture.mmd

# Analyze a single file
py-code-visualizer my_module.py --format html -o my_module.html

Filtering

# Focus on specific modules
py-code-visualizer /path/to/project --modules myapp.core myapp.utils

# Exclude test files
py-code-visualizer /path/to/project --exclude tests migrations

# Limit to functions within 3 calls of main()
py-code-visualizer /path/to/project --entry main.main --depth 3

# Limit graph size for very large projects
py-code-visualizer /path/to/project --max-nodes 100

With Custom Output

py-code-visualizer /path/to/project \
    --format html \
    --output docs/architecture.html \
    --project-name "My Awesome Project" \
    --exclude tests \
    --max-nodes 150 \
    --verbose

๐Ÿ“Š Output Formats

Interactive D3.js HTML

The default --format html produces an interactive visualization with:

  • ๐Ÿ” Search - Find functions by name
  • ๐ŸŽš๏ธ Filters - Filter by module or function type
  • ๐Ÿ”„ Zoom/Pan - Navigate large graphs
  • ๐ŸŒ™ Dark Mode - Toggle light/dark theme
  • ๐Ÿ“Š Statistics - See function count, calls, and cycles
  • โฌ‡๏ธ Export - Download as SVG

Mermaid Diagrams

The --format mermaid produces diagrams that render natively in:

  • GitHub README and Issues
  • GitLab Markdown
  • VS Code with Mermaid extension
  • Any Mermaid-compatible viewer

Example output:

flowchart LR
    subgraph module["myapp"]
        subgraph cls["MyClass"]
            init["__init__"]
            process["process"]
        end
        main["main"]
    end
    main --> init
    main --> process

๐Ÿ”„ CI/CD Integration

Auto-Update Diagrams on Push

Add .github/workflows/auto-diagram.yml (included in this repo):

name: Update Architecture Diagrams

on:
  push:
    branches: [main]
    paths: ['**/*.py']

jobs:
  update-diagrams:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-python@v5
      with:
        python-version: '3.11'
    
    - name: Install PyVisualizer
      run: pip install py-code-visualizer
    
    - name: Generate diagrams
      run: |
        py-code-visualizer . \
          --format mermaid \
          --output docs/architecture.mmd \
          --exclude tests
    
    - name: Commit changes
      run: |
        git config user.name "github-actions[bot]"
        git config user.email "github-actions[bot]@users.noreply.github.com"
        git add docs/
        git diff --staged --quiet || git commit -m "๐Ÿ—๏ธ Update architecture diagrams"
        git push

PR Architecture Review

Add .github/workflows/pr-diagram.yml (included in this repo) to automatically post architecture analysis as a PR comment.

๐Ÿ› ๏ธ Development

# Clone and install dev dependencies
git clone https://github.com/haider1998/PyVisualizer.git
cd PyVisualizer
pip install -e ".[dev]"

# Run tests
make test

# Format code
make format

# Run linters
make lint

# Generate architecture diagram of PyVisualizer itself
make self-viz

๐Ÿ“ Project Structure

pyvisualizer/
โ”œโ”€โ”€ pyvisualizer/              # Main package
โ”‚   โ”œโ”€โ”€ cli.py                 # CLI entry point
โ”‚   โ”œโ”€โ”€ core/                  # Analysis modules
โ”‚   โ”‚   โ”œโ”€โ”€ analyzer.py        # AST parsing
โ”‚   โ”‚   โ”œโ”€โ”€ graph.py           # Call graph building
โ”‚   โ”‚   โ””โ”€โ”€ resolver.py        # Function resolution
โ”‚   โ”œโ”€โ”€ visualizers/           # Output generators
โ”‚   โ”‚   โ”œโ”€โ”€ mermaid.py         # Mermaid diagrams
โ”‚   โ”‚   โ””โ”€โ”€ d3.py              # Interactive D3.js
โ”‚   โ””โ”€โ”€ utils/                 # Utilities
โ”‚       โ””โ”€โ”€ file_discovery.py
โ”œโ”€โ”€ tests/                     # Test suite
โ”œโ”€โ”€ examples/                  # Example projects
โ”œโ”€โ”€ .github/workflows/         # CI/CD pipelines
โ””โ”€โ”€ docs/                      # Documentation

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments


Made with โค๏ธ by Syed Mohd Haider Rizvi

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

py_code_visualizer-1.0.1.tar.gz (32.4 kB view details)

Uploaded Source

Built Distribution

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

py_code_visualizer-1.0.1-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_code_visualizer-1.0.1.tar.gz
  • Upload date:
  • Size: 32.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for py_code_visualizer-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ba98d96a5715e2b612ce3283dd0fc98936bd37a992840075ecba8446c31f867c
MD5 50bb482c5e018ebea0d9e0553a1cf19b
BLAKE2b-256 2415f42fe30937e203bba8c5ba6b06d7cc2679cb6c377699ae4a70a93f7770ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_code_visualizer-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f794d13d3cc4cbb55c7f35fd52985d3dbd979c3e39b22fe3bb47b8dbbf2ef17c
MD5 e6febb6c86d59440e88db8c84c3395f3
BLAKE2b-256 54bd6c7496f920ccd2093ef8cfe012ca4549cc7e404d4ce4b9bcd8bebdc1ea10

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