Transform complex Python codebases into beautiful interactive diagrams
Project description
๐จ PyVisualizer
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.
โจ 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.
- 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
๐ 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba98d96a5715e2b612ce3283dd0fc98936bd37a992840075ecba8446c31f867c
|
|
| MD5 |
50bb482c5e018ebea0d9e0553a1cf19b
|
|
| BLAKE2b-256 |
2415f42fe30937e203bba8c5ba6b06d7cc2679cb6c377699ae4a70a93f7770ab
|
File details
Details for the file py_code_visualizer-1.0.1-py3-none-any.whl.
File metadata
- Download URL: py_code_visualizer-1.0.1-py3-none-any.whl
- Upload date:
- Size: 35.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f794d13d3cc4cbb55c7f35fd52985d3dbd979c3e39b22fe3bb47b8dbbf2ef17c
|
|
| MD5 |
e6febb6c86d59440e88db8c84c3395f3
|
|
| BLAKE2b-256 |
54bd6c7496f920ccd2093ef8cfe012ca4549cc7e404d4ce4b9bcd8bebdc1ea10
|