IMPORTANT NOTICE: This repository (the Python-based
graphify-opt) has been officially deprecated and is no longer maintained (EOL). All core features, optimizations, and capabilities have been fully rewritten and migrated to our 100% native Rust-based codebase!π Why you should migrate to GraphifyRust:
- 26x+ Faster Parsing: Static AST extraction and graph construction completes in less than 16ms (compared to 420ms+ in Python) for medium codebases.
- 60% Token & Storage Savings: Native first-class support for the ultra-compact
.toonformat, and virtual serialization-time hyperedge aggregation.- 0 Dependency Executable: Distributed as a single compiled binary without needing Python, PyTorch, C/C++ FFI setup, or Docker.
- Built-in MCP Server: Out-of-the-box MCP integration supporting graph BFS, shortest-path, and real-time incremental reindexing.
π Please migrate immediately to the official Rust version: cawa0505/graphify-rust
Based on graphify v0.9.25 by Safi Shamsi (Apache-2.0 + MIT).
Upstream: https://github.com/Graphify-Labs/graphify
Custom fork optimized with compiled C & Rust engines to bypass Python execution bottlenecks, featuring structured configuration, automatic key rotation, native S-expression queries, structural incremental caching, and token-saving skeleton pruning.
- Install
- 1. Robust Configuration & API Key Resilience
- 2. Local AST Parsing Acceleration
- 3. LLM Cost & Token Optimizations
- 4. CLI & Compatibility Patches
- Performance & Cost Benchmarks
- Backward Compatibility & Seamless Migration
For CLI tools like graphify, using uv's dedicated tool manager is highly recommended as it installs the tool in an isolated virtual environment and exposes the executable globally without polluting your system Python:
# Install globally in an isolated environment (Recommended)
uv tool install graphify-opt
# Run instantly on-the-fly without installing
uvx --from graphify-opt graphify update .# Standard pip installation
pip install graphify-opt
# Using uv pip (active virtualenv)
uv pip install graphify-opt
# Install with SQL support
pip install "graphify-opt[sql]"
# Install with Gemini LLM support
pip install "graphify-opt[gemini]"# install from GitHub
pip install git+https://github.com/cawa0505/graphify@v8
# install with SQL support from GitHub
pip install "graphify[sql] @ git+https://github.com/cawa0505/graphify@v8"Requires Python 3.10+.
These enhancements ensure graphify runs continuously and reliably without requiring complex environment variable setups or manual intervention.
Allows setting up backends, providers, and extraction settings in a single JSON file. Supports per-provider overrides:
{
"backend": "gemini",
"providers": {
"gemini": {
"api_key": ["key1", "key2", "key3"],
"model": "gemini-3-flash-preview",
"extraction": {
"chunk_size": 2
}
},
"openai": {
"api_key": "sk-xxx",
"base_url": "https://your-proxy/v1",
"model": "qwen2.5-coder-7b"
}
},
"extraction": {
"chunk_size": 1,
"max_concurrency": 1,
"max_completion_tokens": 8192
}
}- Overriding:
providers.<backend>.extractionoverrides global settings (e.g., setting Geminichunk_size: 2to stay under free-tier limits). - Backward-compatible with the old flat config format as fallback.
The api_key field accepts a string or list of strings. When a daily quota limit is reached (RESOURCE_EXHAUSTED / 429), graphify immediately rotates to the next available API key and retries the request without sleeping.
- Works seamlessly in both
_call_openai_compat(file relationship extraction) and_call_llm(community cluster labeling). - Multiplies free-tier quotas (e.g., 4 keys Γ 20 requests/day = 80 requests/day).
Adds robust automatic retries on rate limits and temporary server unavailability:
- Parses
retryDelaydirectly from Gemini's JSON error response, falling back to a custom exponential backoff. - Triggers on both 429 (rate limits) and 503 (temporary service unavailability).
- Maximum retries are configurable via
extraction.max_retries(default: 20).
These optimizations remove CPU bottlenecks and memory overhead during local repository analysis, making graph generation extremely fast.
Replaced slow recursive pure-Python AST tree walks with native Tree-Sitter S-Expression Queries ((import_from_statement) @import_from, (call function: (identifier)) @call). This shifts structural syntax matching into compiled C space, speeding up Python AST facts extraction by 10x to 50x.
Unified JavaScript and TypeScript analysis. Previously, the parser performed 4 separate deep recursive walks over the same file's syntax tree to extract imports, exports, aliases, and classes. These are now combined into exactly 1 single-pass iterative DFS walk, cutting walking overhead and redundant disk access by 400%.
Replaced the default tiktoken library with gigatoken (a highly-optimized Rust BPE tokenizer with drop-in .as_tiktoken() compatibility) utilizing an openai-community/gpt2 proxy encoding.
- Includes robust special-token handling (
allowed_special="all") to prevent crashes on raw document strings like<|endoftext|>(prevents tokenizerValueErrorcrashes when scanning raw document strings, markdown files, or prompt injection test suites inside code files). - Accelerates chunk packing token estimation on large codebases.
Introduces an adaptive JSON compatibility layer (graphify/json_compat.py) that dynamically leverages the Rust-compiled orjson library when available.
- 3x to 10x JSON Speedup: Accelerates massive
graph.jsonserialization, deserialization, and high-frequency cache reads/writes during large scans. - Zero-Friction Fallback: Automatically and gracefully falls back to Python's standard
jsonmodule with identical signatures iforjsonis not installed.
Implements an extremely fast dual-layer caching mechanism during cross-file symbol and export path resolution in resolution.py.
-
$O(1)$ Flattened Resolution: Fully memoizes recursive export tracing and file-level local alias resolutions, flattening complex lookup complexities to$O(1)$ and reducing processing times to virtually zero in large codebases. - Star & Wildcard Resiliency: Prevents recursive redundant walks over multi-layer module structures (such as index file re-exports or star wildcards).
These patches reduce input token size and prompt volume, drastically reducing LLM API consumption costs on large scale scans.
Prior to packing files and dispatching them to the LLM, graphify dynamically prunes function, method, and class bodies across Python, JS, TS, Go, Rust, C++, C, Java, PHP, Kotlin, and Swift, leaving behind clean structural interfaces (... or { ... }) and docstrings.
- 70% to 90% Input Token Savings: Deletes non-essential implementation details, keeping only the logical interfaces.
- Packing Optimization: Integrates skeleton sizing directly into
_estimate_file_tokens. By correctly reporting the small skeleton size, graphify can pack 3x to 5x more files per chunk, drastically decreasing total LLM API calls and costs.
Prevents redundant LLM API calls on non-logical changes (such as code formatting, adding comments, fixing docstrings, or running linters):
- Tier 1 (Content Hash): Direct content-hash check (instant hit).
- Tier 2 (AST Structure Hash): On Tier 1 miss, computes a logical structure hash of the file's AST (ignoring locations and comments). If structural match exists, loads LLM results and self-heals the Tier 1 cache for subsequent fast-path runs.
- Tier 3 (LLM Call): True cache miss, triggers LLM only on true logical code changes.
- Includes safe isolation: Document files (.md, .txt) skip AST matching to preserve full text semantic accuracy, and pruning sweeps bypass
ast-*.jsonkeys.
Small, important quality-of-life adjustments and stability fixes:
- CLI Config Flags: Adds
--chunk-size N(max files per LLM chunk) and--max-concurrency N(number of parallel workers) flags to override config values on the fly. - Markdown Fence Stripping: Automatically cleans up and extracts JSON from models that wrap responses in
```json ```code blocks. - Robust Parallel Extractor: Adds
**kwargssupport toextract_corpus_parallel()to prevent method signature crashes when passing custom run options. - Partial Import Resilience: Implemented a
_partial_source_filesstub to prevent schema import crashes when the LLM returns incomplete file paths.
The following metrics are measured on a representative medium-to-large software repository (~100 code files, ~50,000 lines of code, deep re-exports, and typical style/linter changes):
| Metric | Upstream (graphify) |
Optimized (graphify-opt) |
Speedup / Reduction |
|---|---|---|---|
| AST Tree Traversal | Recursive Python walks (4x redundant walks on JS/TS) | Native C S-Expression queries + 1-pass DFS | π 8x to 15x faster |
| Cross-File Symbol Linking |
|
Double-Layer |
π 98% time reduction ( |
| JSON Serialization & Cache IO | Standard json string allocation |
Rust-compiled orjson SIMD binary writes |
π 3x to 10x faster |
| Total Local Analysis Overhead | ~4.5 seconds | ~0.4 seconds | π ~11x overall CPU speedup |
| Metric | Upstream (graphify) |
Optimized (graphify-opt) |
Token & Cost Savings |
|---|---|---|---|
| Input Tokens per Code File | Full file content (including verbose bodies) | AST-Skeletonized interfaces & signatures | π 70% to 90% token reduction |
| Chunk Packing Density | 2 - 3 raw files per LLM request | 10 - 15 skeletonized files per LLM request | π 3x to 5x higher packing density |
| Total LLM API Calls Required | ~40 requests | ~8 requests | π 80% fewer LLM requests |
| Formatting/Docstring/Comment Changes | Cache invalidated |
AST Structural Hash hit |
π 100% cost avoidance on non-logical edits |
graphify-opt is engineered with an absolute commitment to zero-friction backward compatibility. If you are upgrading from standard graphify or an older custom fork:
- 100% Zero-Touch Migration: All of your existing local caches, generated graphs (
graphify-out/), and configuration files (config.json) are 100% fully backward-compatible. No files need to be deleted, rebuilt, or migrated. - Self-Healing Cache Layer: The new 3-tier AST-based caching layer automatically integrates with your old content-hash caches. It self-heals by back-propagating AST matches into standard raw-hash caches natively on first run.
- Opt-In High Performance: The Rust-compiled JSON acceleration (
orjson) is completely optional. Iforjsonis not installed on your system,graphify-optwill gracefully fallback to standard libraryjsonand work flawlessly. Installorjsonat any time (pip install orjson) to instantly unlock 10x serialization speedups with zero configuration required.