rand/calligrapher
A high-performance, modular static analysis tool written in Zig that generates enriched call graphs for multiple programming languages using tree-sitt...
A fast, memory-safe static call graph analyzer for Python, written in Zig.
Calligrapher analyzes Python code to extract call graphs enriched with cyclomatic complexity metrics, control flow analysis, and powerful query operations. Built with tree-sitter for fast, error-tolerant parsing.
Prerequisites:
Build from source:
git clone https://github.com/rand/calligrapher.git
cd calligrapher
zig build
Binary available at zig-out/bin/calligrapher.
# Analyze a Python file and generate call graph with metrics
zig build run -- enrich examples/python/minimal/project.py -o output.json
# Analyze entire project directory (multi-file)
zig build run -- enrich examples/python/multi_module/ -o project_output.json
# Export project manifest
zig build run -- enrich ./my_project --manifest -o manifest.json
# Generate GraphViz visualization
zig build run -- enrich examples/python/with_classes/shapes.py --format=dot -o graph.dot
dot -Tpng graph.dot -o graph.png
# Generate Mermaid diagram
zig build run -- enrich examples/python/with_types/types_demo.py --format=mermaid -o diagram.mmd
# Query operations
zig build run -- query output.json find Circle
zig build run -- query output.json callers module.function
zig build run -- query output.json path from_func to_func
After running enrich, you'll see project metrics:
Project Metrics Summary
=======================
Complexity Distribution:
Low (1-5): 15 functions (75.0%)
Moderate (6-10): 4 functions (20.0%)
High (11-20): 1 function (5.0%)
Very High (21+): 0 functions (0.0%)
Statistics:
Mean complexity: 4.2
Median complexity: 3.0
Std deviation: 2.1
Top 5 Most Complex Functions:
1. module.process_data (complexity: 12)
2. module.validate_input (complexity: 8)
...
Structured data with symbols, call graph, complexity metrics, and control flow:
zig build run -- enrich file.py -o output.json
Visual graphs with complexity-based coloring:
zig build run -- enrich file.py --format=dot -o graph.dot
dot -Tpng graph.dot -o graph.png
GitHub/GitLab compatible diagrams:
zig build run -- enrich file.py --format=mermaid -o diagram.mmd
# Find symbols by name (partial match)
zig build run -- query output.json find symbol_name
# Find who calls this function
zig build run -- query output.json callers module.function
# Find what this function calls
zig build run -- query output.json callees module.function
# Find shortest path between functions
zig build run -- query output.json path from_func to_func
# Find all paths (depth-limited to 10)
zig build run -- query output.json allpaths from_func to_func
Cyclomatic Complexity Ranges:
Control Flow Metrics:
Project Statistics:
See PERFORMANCE.md for detailed benchmarks.
# Run all tests
zig build test
# Run release testing script
./scripts/test_release.sh
# Run performance benchmarks
./scripts/benchmark.sh
Test Coverage:
The examples/python/ directory contains sample projects:
Each example includes expected output for validation.
Calligrapher uses a modular pipeline architecture:
Input Python → Tree-sitter Parser → Symbol Extraction → Name Resolution
↓
Complexity Computation
↓
Call Graph Construction
↓
Export (JSON/DOT/Mermaid) or Query
Modules:
See API.md for detailed architecture documentation.
See PROJECT_PLAN.md for detailed roadmap.
Contributions welcome! See API.md for guides on:
Please open an issue or PR referencing relevant items in STATUS.md.
Calligrapher is distributed under the MIT License.
Version 0.1.0 | October 13, 2025 | Initial Release