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.
[!WARNING] ⚠️ Caution: Potential LLM API Usage Costs
pystdocperforms thorough, multi-pass analysis by sending prompts for individual symbols, modules, and architecture synthesis. When using commercial paid API endpoints (such as OpenAI GPT-4, Claude, etc.), analyzing large codebases can consume a significant amount of tokens and may incur substantial financial costs. We strongly recommend using self-hosted/local LLM backends (e.g., LiteRT-LM, Ollama, vLLM, or LocalAI) or setting strict API budget limits before running against large projects.
📁 Output Directory: .docgen/
[!IMPORTANT] All generated documentation, architecture designs, and caches are automatically centralized inside the
.docgen/directory of your target project. Your existing source code files are never modified.
When pystdoc finishes, you can explore the complete documentation suite starting from .docgen/README.md:
your_project/
├── .docgen/ # <-- 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
│ └── 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.
- 3-in-1 Unified Documentation Pipeline:
docgen: Bottom-up & top-down symbol-level documentation with SHA-256 and SQLite caching (.docgen/documents/).designgen: Map-Reduce architectural synthesis (.docgen/design/).reportgen/pystdoc: Executive summary README (.docgen/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++:
- 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(e.g.English,Japanese,日本語).
🚀 Quick Start
Installation
pip install pystdoc
Basic Usage
1. Generate & Sync Full Documentation Suite (sync / Default)
# Generate complete documentation (symbol docs, design docs, README overview)
pystdoc --dir ./my_project/
# Or explicitly with sync subcommand
pystdoc sync --dir ./my_project/ --language 日本語
2. Inspect & Query Indexed Codebase (Read from .docgen/)
Once .docgen/ 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, funcs, fns
pystdoc fn
# List all variables, constants, and fields
pystdoc variables
# Aliases: var, vars
pystdoc var
# 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
3. Practical Real-World Example (Dedicated Remote LLM Server)
pystdoc sync --dir ./target_project/ --host 192.168.0.123:11434 --model gemma4-26b-a4b --language 日本語
🛠️ 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. |
list |
ls |
List all indexed source files from .docgen/. |
functions |
fn, func, funcs, fns |
List all indexed functions/methods with source location (<file>:<from>:<to>). |
variables |
var, vars |
List all indexed variables, constants, and data model fields with location. |
description |
desc |
Display rich purpose, overview, signature, and source location for specified symbol or FQDN. |
⚙️ CLI Options (for sync / pystdoc)
| Option | Alias / Env | Default | Description |
|---|---|---|---|
--dir |
./ |
Target project directory path | |
--language |
-l |
English |
Output documentation language (English, Japanese, 日本語) |
--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 |
--compile-commands |
None |
Path to compile_commands.json |
📄 License
MIT License. Author: tab4moji.
Metadata
Release files for pystdoc 0.5.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pystdoc-0.5.8.tar.gz | 88.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pystdoc-0.5.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 153.0 kB
Release files / pystdoc-0.5.8.tar.gz
| Download URL | pystdoc-0.5.8.tar.gz |
|---|---|
| Size | 88.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6229b33c4e74e8e978ab2870772b8e3aa49d852bfefdeb09eb71bc03502c9665
|
|
BLAKE2b-256 checksum How to use checksums |
b887c1b4af75da5b0083b79df23be95a15fad2dbc21fa24636ca029d94f8a6e5
|
| 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.5.8-py3-none-any.whl
| Download URL | pystdoc-0.5.8-py3-none-any.whl |
|---|---|
| Size | 64.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
65505c85912a114ca44a41c9ece9530a8d55b18ef65475861f72cae71eec14db
|
|
BLAKE2b-256 checksum How to use checksums |
403e5d2b8d25deedbfcf2c8967e986b56948d6c94d8aa890e4a8290c38f88af8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|