Skip to content

haider1998/pyvisualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎨 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
Loading

πŸ”„ 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

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors