pystdoc: Python Structural & Topological Documentation Engine
pystdoc (Python Structural & Topological Documentation Engine) is an enterprise-grade, high-precision codebase and architectural documentation generator powered by LLMs, AST parsing, and libclang.
It analyzes codebases in bottom-up + top-down topological passes, constructs hierarchical execution/data models, and synthesizes clean, human-centric Markdown and Mermaid diagrams within a 16K context window.
📁 Output Directory: .pystdoc/
When pystdoc finishes, you can explore the complete documentation suite starting from .pystdoc/README.md:
your_project/
├── .pystdoc/ # <-- Centralized output directory
│ ├── README.md # Executive summary: "What does this project actually do?"
│ ├── design/ # System architecture and design documentation
│ │ ├── overview.md # Architecture overview & inter-module Mermaid diagram
│ │ ├── data_models.md # Data structure design, models, lifecycle & integrity
│ │ ├── execution_model.md # Runtime execution model, paradigms, & control flow
│ │ └── modules/ # Module-by-module detailed design documents
│ │ ├── module_a.md
│ │ └── ...
│ ├── documents/ # Granular symbol & source code documentation
│ │ ├── src/main.c.md # File-level overview and symbol list
│ │ ├── src/main.c.fn.main.md # Individual symbol document (with call graph & context)
│ │ └── ...
│ ├── files.txt # List of scanned source files
│ ├── document_labels.json # Localized titles/headings (editable)
│ └── index.db # SQLite WAL database for instantaneous incremental caching
├── src/
└── ...
🌟 Key Features
- Topological & Structural Ordering (Tarjan SCC + Kahn DAG):
- Evaluates call graphs in $O(V+E)$ linear time.
- Automatically breaks cyclic mutual recursions and organizes code symbols into dependency-safe execution levels.
- Level-by-level parallel LLM execution guarantees context-rich bottom-up summaries without race conditions.
- High-Speed Incremental Sync & Semantic Change Propagation (v0.8.0 - v0.8.5):
- Selective Bottom-Up Propagation & Immediate Snippet Flush: Detects AST and logic-level code differences. If regenerated specifications remain semantically unchanged, cascading LLM re-analysis terminates early while Markdown documents (source code snippets, line ranges, caller/callee references) are immediately updated with latest code. Signature, kind, and callee alterations are guaranteed to propagate upstream.
- Content-Defined Map-Reduce Caching: Intermediate summaries in architecture synthesis (
designgen) are chunked using stable hash boundaries and cached per group in SQLite, ensuring that only groups containing edited functions are re-summarized. - Architectural Entry-Point Filtering: For system execution modeling (
execution_model.md), key architectural functions (entry points, CLI routers, and core dispatchers) are automatically filtered and passed directly into the LLM context, bypassing heavy multi-step Map-Reduce loops and speeding up generation by up to 90%+.
- Flexible Step Execution & High-Precision UI Inference (v0.8.1):
- Phase Re-execution & Recovery (
--from-step,--step): Resume or selectively re-run pipeline stages (e.g.,--from-step 3to restart from architecture design, or--step 4for README synthesis only) without regenerating bottom-up symbol documents. - High-Precision UI & CLI Prioritization: Restricts GUI classification to high-confidence UI frameworks (
PyQt,Tkinter,GTK,Jetpack Compose, etc.) while eliminating False Positive hallucinations (e.g. JavaFX). Heavily prioritizes CLI classification for command pipelines and automatically overwrites existing symbol annotations on re-runs.
- Phase Re-execution & Recovery (
- 3-in-1 Unified Documentation Pipeline:
docgen: Bottom-up & top-down symbol-level documentation with SHA-256 and SQLite caching (.pystdoc/documents/).designgen: Map-Reduce architectural synthesis (.pystdoc/design/).reportgen/pystdoc: Executive summary README (.pystdoc/README.md) answering "What does this project actually do?"
- Multi-Language Codebase Deep Understanding (C/C++, Python, Java, Kotlin, Shell):
- C/C++:
compile_commands.jsonintegration, include path resolution, and macro expansion vialibclang. - Java / Kotlin: AST parsing via
javalang&kopytwith class hierarchy, companion objects, and data classes. - Python & Shell: AST visitor and generic regex parser with import/call extraction.
- Fully Qualified Domain Names (FQDN): Disambiguates identical symbol names across large monorepos.
- C/C++:
- Feature Location & UI Component Pinpointing (
locate/pystdoc_locate_feature):- Pinpoint exact files, functions, UI elements, and line ranges (
Lines X-Y) from high-level natural language queries (e.g., "where is the debug notification button", "add auth header") without running brute-forceGlob/Grepacross the entire project. - Built-in multi-lingual token scoring with automatic boosting for UI elements (
@Composable,Button,Dialog,Activity,Modifier, etc.).
- Pinpoint exact files, functions, UI elements, and line ranges (
- Impact & Inbound/Outbound Dependency Analysis (
impact/pystdoc_trace_impact):- Instant 360-degree dependency tracing: inspect where a symbol is called from (Inbound Callers / References) and what it uses (Outbound Dependencies) before making breaking code changes or deletions.
- Standard LLM Options & Multi-Language Support:
- Works with Ollama, LiteRT-LM, vLLM, and OpenAI API.
- Supports
--host,--model,--token/--api-key,--context-size, and--language(defaults to terminal language, e.g.Japanese,English,日本語). - Localized Headings & Titles (v0.8.7): Titles and section headings of all outputs — symbol documents (
documents/), architecture design documents (design/:overview.md,data_models.md,execution_model.md,modules/*.md), and the README — are translated into the target language and stored in.pystdoc/document_labels.json(design/README headings were previously always English). - Robust Label Translation for Small LLMs (v0.8.7): Labels are translated in small chunks with retry, so small local models (e.g.
gemma4:e2b) work. If translation is incomplete, a warning is printed and only the untranslated labels are retried on the next run; manual edits todocument_labels.jsonare preserved. To re-localize existing English output, delete.pystdoc/document_labels.jsonand re-run with--force. designgenparses symbol documents using the localized headings, so it works with documents written in any language.
🚀 Quick Start
Installation
pip install pystdoc
Basic Usage
1. Generate & Sync Documentation Suite (sync / Default)
# Full sync: complete 4-step pipeline (symbol docs, design docs, README overview)
pystdoc --dir ./my_project/
# Partial / Step-level re-run: resume pipeline from Step 3 (designgen) to Step 4 (reportgen)
pystdoc --dir ./my_project/ --from-step 3
# Single-step re-run: regenerate project overview README (.pystdoc/README.md) only
pystdoc --dir ./my_project/ --step 4
# Fast sync: bottom-up symbol analysis & indexing only (skips top-down design/report synthesis)
pystdoc sync --fast --dir ./my_project/
# Explicitly with sync subcommand and options
pystdoc sync --dir ./my_project/ --language 日本語
2. Inspect & Query Indexed Codebase (Read from .pystdoc/)
Once .pystdoc/ is generated, you can query symbols, functions, variables, and files without touching LLMs:
# List all indexed source code files
pystdoc list ./my_project/
# Alias: ls
pystdoc ls
# List all functions and methods with file & line ranges (<name> (<file>:<from>:<to>))
pystdoc functions
# Aliases: fn, func, function, funcs, fns
pystdoc fn
# Inspect specific function description directly (shortcut for desc)
pystdoc fn processData
# List all variables, constants, and fields
pystdoc variables
# Aliases: var, variable, vars
pystdoc var
# Inspect specific variable description directly
pystdoc var CONFIG_TIMEOUT
# List all types, classes, structs, enums, and interfaces
pystdoc types
# Aliases: type, class, classes, struct, structs
pystdoc type
# Inspect specific type or class description directly
pystdoc type MainViewModel
pystdoc class UserModel
# Inspect detailed description, purpose, overview, and signature of a symbol
pystdoc description Userlib.main
# Alias: desc (Supports dot notation, C++ scope resolution, and short names)
pystdoc desc Userlib::main
pystdoc desc logMessage
# Locate feature, UI component, or line ranges by natural language query
pystdoc locate "デバッグ通知ボタンを消したい"
# Aliases: find, search
pystdoc find "auth header"
pystdoc search "MainViewModel"
# Trace inbound callers and outbound dependencies for impact analysis before modifying code
pystdoc impact MainViewModel.sendNotification
# Aliases: trace, callers
pystdoc trace DebugButton
pystdoc callers processData
3. Continuous File Change Watch & Auto-Sync (watch Mode)
Automatically monitor source code directories via Linux dnotify (and snapshot polling) and auto-sync on file save:
# Start continuous watcher
pystdoc watch --dir ./my_project/
# Or with flag and custom debounce interval (default: 1.0s)
pystdoc --watch --interval 0.5
4. Practical Real-World Example (Dedicated Remote LLM Server)
# Production execution with dedicated local/remote server
pystdoc sync --dir ./target_project/ --host 192.168.0.11:11434 --model gemma4-26b-a4b --language 日本語
# Debugging LLM responses in realtime (tail -f tmp.debug.log in another terminal)
pystdoc sync --dir ./target_project/ --debug
🛠️ CLI Subcommands & Commands Overview
| Subcommand | Aliases | Description |
|---|---|---|
sync |
(default) | Run full 3-in-1 unified pipeline: parse code, generate symbol docs, architecture design, and project README. |
watch |
monitor |
Continuously watch source directories for changes (dnotify / mtime) and auto-sync on save. |
locate |
find, search |
Locate candidate files, functions, UI components, or line ranges matching a feature description or query. |
impact |
trace, callers |
Trace inbound callers and outbound dependencies of a symbol for impact analysis before modifying or deleting code. |
list |
ls |
List all indexed source files from .pystdoc/. |
functions |
fn, func, function, funcs, fns |
List all functions/methods, or inspect <name> description directly (fn <name>). |
variables |
var, variable, vars |
List all variables/constants/fields, or inspect <name> description directly (var <name>). |
types |
type, class, classes, struct, structs |
List all types/classes/structs/enums, or inspect <name> description directly (type <name>). |
description |
desc |
Display rich purpose, overview, signature, and source location for specified symbol or FQDN. |
mcp |
serve, server |
Run Model Context Protocol (MCP) stdio server for OpenCode / AI coding agents. |
🔧 Configuration File (~/.config/pystdoc/pystdoc.json)
pystdoc automatically loads defaults from ~/.config/pystdoc/pystdoc.json (or ./.pystdoc.json for per-project configuration). This allows commands and MCP servers to run without passing long CLI flags.
{
"host": "http://192.168.0.123:11434",
"model": "gemma4-26b-a4b",
"language": "Japanese",
"context_size": 16384,
"concurrency": 2,
"allow_fallback": true,
"token": null
}
Precedence Resolution:
- CLI Flags (
--host,--model,-l, etc.) - Environment Variables (
LLM_HOST,LLM_MODEL,OPENAI_API_KEY, etc.) - Project Config (
<project>/.pystdoc.json) - User Config (
~/.config/pystdoc/pystdoc.json) - Builtin Defaults (
http://127.0.0.1:11434,gemma4-26b-a4b, Terminal language /English)
🔌 Model Context Protocol (MCP) Server
pystdoc includes a built-in MCP server (pystdoc mcp) for OpenCode, Claude Desktop, and other MCP-compatible AI agents. It enables small local LLMs to retrieve targeted AST structures and symbol docs on-demand without loading multi-thousand-line source files into context.
OpenCode Configuration (~/.config/opencode/opencode.json)
{
"mcp": {
"pystdoc": {
"type": "local",
"command": [
"uv",
"run",
"pystdoc",
"mcp"
]
}
}
}
Tools Provided by MCP Server:
pystdoc_get_overview(path): Retrieve the executive summary (README.md) and high-level architectural overview (overview.md) in one call.pystdoc_locate_feature(query, path): Find candidate file locations, UI components, and line ranges (Lines X-Y) for a feature or bug fix. Use this instead of grep/glob.pystdoc_trace_impact(symbol, path): Trace inbound callers and outbound dependencies of a symbol to determine ripple effects before modifying or deleting code.pystdoc_search_symbols(query, kind, path): Search indexed symbols by keyword/substring, returning their FQDN, file location, and purpose summary.pystdoc_get_symbol(symbol, path): Retrieve rich purpose, overview, signature, line ranges, and markdown snippet for a specific symbol.pystdoc_list_symbols(kind, path): List indexed symbols (function,variable,type, orall) with definition line ranges (file:from:to).pystdoc_get_design(section, path): Retrieve architecture design docs (readme,overview,data_models,execution_model, or module names likeMainViewModel).pystdoc_list_files(path): List all indexed source code files.pystdoc_sync(path, fast, no_llm, language): Generate or update documentation suite. Recommended for OpenCode: Usefast=Trueduring active coding to rapidly refresh symbol and call-graph indexes without top-down synthesis overhead.
⚙️ CLI Options (for sync / pystdoc)
| Option | Alias / Env | Default | Description |
|---|---|---|---|
--dir |
./ |
Target project directory path | |
--from-step |
None |
Start pipeline from specific step (1..4, docgen, data, design, report) |
|
--step |
None |
Run only the specified step (1..4, docgen, data, design, report) |
|
--fast |
false |
Fast bottom-up sync only (runs docgen symbol indexing, skips designgen and reportgen) | |
--skip-docgen |
false |
Skip Step 1 & 2 (source parsing and symbol document generation) | |
--skip-designgen |
false |
Skip Step 3 (architectural design and module synthesis) | |
--language |
-l |
Terminal locale | Output documentation language (defaults to terminal language; e.g. Japanese, English, 日本語) |
--host |
-H, --base-url |
http://127.0.0.1:11434 |
LLM server host endpoint URL |
--model |
-m, LLM_MODEL |
gemma4-26b-a4b |
LLM model identifier |
--token |
--api-key, OPENAI_API_KEY |
None |
API Bearer token |
--context-size |
--ctx-size |
16384 |
Context window size |
--concurrency |
-j |
1 |
Number of parallel LLM workers |
--force |
-f |
false |
Force regenerate all documents ignoring cache |
--debug |
PYSTDOC_DEBUG |
false |
Enable realtime LLM request and streaming token logging to tmp.debug.log |
--compile-commands |
None |
Path to compile_commands.json |
📄 License
MIT License. Author: tab4moji.
Metadata
Release files for pystdoc 0.8.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pystdoc-0.8.7.tar.gz | 178.1 kB | Without provenance | Details for pystdoc-0.8.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pystdoc-0.8.7-py3-none-any.whl | Python 3 | none | any | Details for pystdoc-0.8.7-py3-none-any.whl |
Total release size: 300.4 kB
Release files / pystdoc-0.8.7.tar.gz
| Download URL | pystdoc-0.8.7.tar.gz |
|---|---|
| Size | 178.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
25973c6b72a26352fadca608387d827658ed029863fea613eb65daa3b48b6025
|
|
BLAKE2b-256 checksum How to use checksums |
2dfe9f193aac7632bdd1a359bc415620f6aeaa09693bbe5e55cdd9ed19bc7b18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / pystdoc-0.8.7-py3-none-any.whl
| Download URL | pystdoc-0.8.7-py3-none-any.whl |
|---|---|
| Size | 122.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3ff9bdc2ab030bc1a302130318b9c7992bfe3d61c1b26e8d79608edd0755c3a6
|
|
BLAKE2b-256 checksum How to use checksums |
2f789f78d0c958c704f50a4770b7b5e8687388ddeec0bba1fc5acc8d727c05f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Security for pystdoc 0.8.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.