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.
- 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
- 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)
- Filter by specific modules
- Exclude test files or other patterns
- Limit call depth from entry points
- Control maximum nodes for large codebases
- GitHub Actions workflows included
- Auto-update diagrams on commit
- PR review with architecture analysis
pip install py-code-visualizerOr 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# 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# 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 100py-code-visualizer /path/to/project \
--format html \
--output docs/architecture.html \
--project-name "My Awesome Project" \
--exclude tests \
--max-nodes 150 \
--verboseThe 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
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
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 pushAdd .github/workflows/pr-diagram.yml (included in this repo) to automatically post architecture analysis as a PR comment.
# 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-vizpyvisualizer/
βββ 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
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ by Syed Mohd Haider Rizvi
