Auto-generate and sync project documentation from source code analysis
Project description
AI Cost Tracking
- ๐ค LLM usage: $7.5000 (72 commits)
- ๐ค Human dev: ~$2534 (25.3h @ $100/h, 30min dedup)
Generated on 2026-04-20 using openrouter/qwen/qwen3-coder-next
Auto-generate and sync project documentation from source code analysis.
code2docs uses code2llm's AnalysisResult to produce human-readable documentation: README.md, API references, module docs, usage examples, and architecture diagrams.
code2llm โ AnalysisResult โ .toon / .mmd / context.md (for LLM)
code2docs โ AnalysisResult โ README.md / docs/ / examples/ (for humans)
Installation
pip install code2docs
Or from source:
git clone https://github.com/wronai/code2docs
cd code2docs
pip install -e .
Optional extras
pip install code2docs[watch] # file watcher (watchdog)
pip install code2docs[mkdocs] # MkDocs integration
pip install code2docs[dev] # development tools
Generate full documentation for a project
code2docs ./my-project
Generate only README
code2docs ./my-project --readme-only
Sync (regenerate only changed modules)
code2docs sync ./my-project
Watch mode (auto-resync on file changes)
code2docs watch ./my-project
Initialize config file
code2docs init ./my-project
Dry-run (show what would be generated)
code2docs ./my-project --dry-run
### Python API
```python
from code2docs import generate_readme, generate_docs, Code2DocsConfig
# Generate README
generate_readme("./my-project", output="README.md")
# Generate full docs with custom config
config = Code2DocsConfig(project_name="mylib", verbose=True)
docs = generate_docs("./my-project", config=config)
Generated Output
<project>/
โโโ README.md # Main README (auto-generated sections)
โโโ docs/
โ โโโ index.md # Documentation index
โ โโโ architecture.md # Architecture + Mermaid diagrams
โ โโโ api/
โ โ โโโ index.md # API overview
โ โ โโโ module_analyzer.md # Per-module API reference
โ โ โโโ ...
โ โโโ modules/
โ โโโ analyzer.md # Detailed module documentation
โ โโโ ...
โโโ examples/
โ โโโ basic_usage.py # Auto-generated usage example
โ โโโ class_examples.py # Class usage examples
โ โโโ ...
โโโ code2docs.yaml # Generator configuration
Configuration
Create code2docs.yaml in your project root (or run code2docs init):
project:
name: my-project
source: ./
output: ./docs/
readme:
sections:
- overview
- install
- quickstart
- api
- structure
- endpoints
badges:
- version
- python
- coverage
- complexity
sync_markers: true
docs:
api_reference: true
module_docs: true
architecture: true
changelog: true
examples:
auto_generate: true
from_entry_points: true
sync:
strategy: markers # markers | full | git-diff
watch: false
ignore:
- "tests/"
- "__pycache__"
Sync Markers
code2docs can update only specific sections of an existing README using markers:
<!-- code2docs:start --># code2docs
   
> **276** functions | **57** classes | **51** files | CCฬ = 3.8
> Auto-generated project documentation from source code analysis.
**Author:** Tom Sapletta
**License:** Apache-2.0[(LICENSE)](./LICENSE)
**Repository:** [https://github.com/wronai/code2docs](https://github.com/wronai/code2docs)
### From PyPI
```bash
pip install code2docs
From Source
git clone https://github.com/wronai/code2docs
cd code2docs
pip install -e .
Optional Extras
pip install code2docs[llm] # LLM integration (litellm)
pip install code2docs[git] # Git integration (GitPython)
pip install code2docs[watch] # file watcher (watchdog)
pip install code2docs[mkdocs] # MkDocs integration
pip install code2docs[dev] # development tools
pip install code2docs[all] # all optional features
Generate full documentation for your project
code2docs ./my-project
Only regenerate README
code2docs ./my-project --readme-only
Preview what would be generated (no file writes)
code2docs ./my-project --dry-run
Check documentation health
code2docs check ./my-project
Sync โ regenerate only changed modules
code2docs sync ./my-project
### Python API
```python
from code2docs import generate_readme, generate_docs, Code2DocsConfig
# Quick: generate README
generate_readme("./my-project")
# Full: generate all documentation
config = Code2DocsConfig(project_name="mylib", verbose=True)
docs = generate_docs("./my-project", config=config)
Generated Output
When you run code2docs, the following files are produced:
<project>/
โโโ README.md # Main project README (auto-generated sections)
โโโ docs/
โ โโโ api.md # Consolidated API reference
โ โโโ modules.md # Module documentation with metrics
โ โโโ architecture.md # Architecture overview with diagrams
โ โโโ dependency-graph.md # Module dependency graphs
โ โโโ coverage.md # Docstring coverage report
โ โโโ getting-started.md # Getting started guide
โ โโโ configuration.md # Configuration reference
โ โโโ api-changelog.md # API change tracking
โโโ examples/
โ โโโ quickstart.py # Basic usage examples
โ โโโ advanced_usage.py # Advanced usage examples
โโโ CONTRIBUTING.md # Contribution guidelines
โโโ mkdocs.yml # MkDocs site configuration
Sync Markers
code2docs can update only specific sections of an existing README using HTML comment markers:
<!-- code2docs:start -->
# Project Title
... auto-generated content ...
<!-- code2docs:end -->
Content outside the markers is preserved when regenerating. Enable this with sync_markers: true in your configuration.
Architecture
code2docs/
โโโ registry โโโ llm_helperโโโ code2docs/ โโโ __main__ โโโ 04_sync_and_watch โโโ 05_custom_generators โโโ quickstart โโโ 06_formatters โโโ advanced_usage โโโ 03_programmatic_api โโโ entry_points โโโ 07_web_frameworks โโโ class_examples โโโ basic_usage โโโ 01_cli_usage โโโ 02_configuration โโโ updater โโโ sync/ โโโ watcher โโโ base โโโ quickstart โโโ advanced_usage โโโ markdown โโโ badges โโโ toc โโโ formatters/ โโโ differ โโโ coverage_gen โโโ _source_links โโโ depgraph_gen โโโ getting_started_gen โโโ config_docs_gen โโโ changelog_gen โโโ generators/ โโโ code2llm_gen โโโ module_docs_gen โโโ api_reference_gen โโโ examples_gen โโโ mkdocs_gen โโโ config โโโ api_changelog_gen โโโ _registry_adapters โโโ readme_gen โโโ contributing_gen โโโ analyzers/ โโโ dependency_scanner โโโ endpoint_detector โโโ architecture_gen โโโ project_scanner โโโ docstring_extractor โโโ cli```
### Classes
- **`GeneratorRegistry`** โ Registry of documentation generators.
- **`LLMHelper`** โ Thin wrapper around litellm for documentation generation.
- **`MetricsReportGenerator`** โ Generate a metrics report from code analysis.
- **`APIChangelogGenerator`** โ Generate changelog based on API changes.
- **`CustomGenerator`** โ Example of extending the base generator class.
- **`Updater`** โ Apply selective documentation updates based on detected changes.
- **`GenerateContext`** โ Shared context passed to all generators during a run.
- **`BaseGenerator`** โ Abstract base for all documentation generators.
- **`MarkdownFormatter`** โ Helper for constructing Markdown documents.
- **`ChangeInfo`** โ Describes a detected change.
- **`Differ`** โ Detect changes between current source and previous state.
- **`CoverageGenerator`** โ Generate docs/coverage.md โ docstring coverage report.
- **`SourceLinker`** โ Build source-code links (relative paths + optional GitHub/GitLab URLs).
- **`DepGraphGenerator`** โ Generate docs/dependency-graph.md with Mermaid diagrams.
- **`GettingStartedGenerator`** โ Generate docs/getting-started.md from entry points and dependencies.
- **`ConfigDocsGenerator`** โ Generate docs/configuration.md from Code2DocsConfig dataclass.
- **`ChangelogEntry`** โ A single changelog entry.
- **`ChangelogGenerator`** โ Generate CHANGELOG.md from git log and analysis diff.
- **`Code2LlmGenerator`** โ Generate code2llm analysis files in project/ directory.
- **`ModuleDocsGenerator`** โ Generate docs/modules.md โ consolidated module documentation.
- **`ApiReferenceGenerator`** โ Generate docs/api.md โ consolidated API reference.
- **`ExamplesGenerator`** โ Generate examples/ โ usage examples from public API signatures.
- **`MkDocsGenerator`** โ Generate mkdocs.yml from the docs/ directory structure.
- **`ReadmeConfig`** โ Configuration for README generation.
- **`DocsConfig`** โ Configuration for docs/ generation.
- **`ExamplesConfig`** โ Configuration for examples/ generation.
- **`SyncConfig`** โ Configuration for synchronization.
- **`Code2LlmConfig`** โ Configuration for code2llm analysis generation.
- **`LLMConfig`** โ Configuration for optional LLM-assisted documentation generation.
- **`Code2DocsConfig`** โ Main configuration for code2docs.
- **`ApiChange`** โ A single API change between two analysis snapshots.
- **`ApiChangelogGenerator`** โ Generate API changelog by diffing current analysis with a saved snapshot.
- **`ReadmeGeneratorAdapter`** โ โ
- **`ApiReferenceAdapter`** โ โ
- **`ModuleDocsAdapter`** โ โ
- **`ArchitectureAdapter`** โ โ
- **`DepGraphAdapter`** โ โ
- **`CoverageAdapter`** โ โ
- **`ApiChangelogAdapter`** โ โ
- **`ExamplesAdapter`** โ โ
- **`MkDocsAdapter`** โ โ
- **`GettingStartedAdapter`** โ โ
- **`ConfigDocsAdapter`** โ โ
- **`ContributingAdapter`** โ โ
- **`Code2LlmAdapter`** โ Adapter for code2llm analysis generation.
- **`ReadmeGenerator`** โ Generate README.md from AnalysisResult.
- **`ContributingGenerator`** โ Generate CONTRIBUTING.md by detecting dev tools from pyproject.toml.
- **`DependencyInfo`** โ Information about a project dependency.
- **`ProjectDependencies`** โ All detected project dependencies.
- **`DependencyScanner`** โ Scan and parse project dependency files.
- **`Endpoint`** โ Represents a detected web endpoint.
- **`EndpointDetector`** โ Detects web endpoints from decorator patterns in source code.
- **`ArchitectureGenerator`** โ Generate docs/architecture.md โ architecture overview with diagrams.
- **`ProjectScanner`** โ Wraps code2llm's ProjectAnalyzer with code2docs-specific defaults.
- **`DocstringInfo`** โ Parsed docstring with sections.
- **`DocstringExtractor`** โ Extract and parse docstrings from AnalysisResult.
- **`DefaultGroup`** โ Click Group that routes unknown subcommands to 'generate'.
### Functions
- `detect_changes_example(project_path)` โ Detect what files have changed since last documentation generation.
- `update_docs_incrementally(project_path)` โ Update only the parts of docs that need changing.
- `force_full_regeneration(project_path)` โ Force full regeneration of all documentation.
- `watch_and_auto_regenerate(project_path, interval)` โ Watch for file changes and auto-regenerate documentation.
- `custom_watcher_with_hooks(project_path)` โ Set up a custom watcher with pre/post generation hooks.
- `sync_with_git_changes(project_path)` โ Only regenerate docs for files changed in git.
- `generate_custom_report(project_path)` โ Generate a custom metrics report.
- `markdown_formatting_examples()` โ Demonstrate markdown formatting utilities.
- `generate_complex_document()` โ Generate a complex markdown document using the formatter.
- `badge_examples()` โ Generate various badge examples.
- `toc_examples()` โ Demonstrate table of contents generation.
- `build_custom_readme()` โ Build a custom README using formatters.
- `generate_readme_simple(project_path)` โ Generate README.md content from a project.
- `generate_full_documentation(project_path)` โ Generate complete documentation for a project.
- `custom_documentation_pipeline(project_path)` โ Create a custom documentation pipeline.
- `inspect_project_structure(project_path)` โ Inspect project structure from analysis.
- `generate_docs_if_needed(project_path, force)` โ Only generate docs if code has changed.
- `detect_flask_endpoints(project_path)` โ Detect Flask endpoints in a project.
- `detect_fastapi_endpoints(project_path)` โ Detect FastAPI endpoints in a project.
- `generate_api_docs_from_endpoints(project_path, output_dir)` โ Generate API documentation from detected endpoints.
- `create_example_web_apps(target_dir)` โ Create example Flask and FastAPI apps for testing.
- `document_web_project(project_path)` โ Complete workflow: detect endpoints and generate docs.
- `run_cli_basic(project_path)` โ Run code2docs CLI programmatically.
- `run_cli_with_config(project_path, config_path)` โ Run with custom configuration.
- `create_basic_config()` โ Create a basic configuration.
- `create_advanced_config()` โ Create advanced configuration with all options.
- `save_yaml_config_example(path)` โ Save example YAML config to file.
- `load_config_from_yaml(path)` โ Load configuration from YAML file.
- `start_watcher(project_path, config)` โ Start watching project for file changes and auto-resync docs.
- `generate_badges(project_name, badge_types, stats, deps)` โ Generate shields.io badge Markdown strings.
- `generate_toc(markdown_content, max_depth)` โ Generate a table of contents from Markdown headings.
- `extract_headings(content, max_depth)` โ Extract headings from Markdown content.
- `generate_docs(project_path, config)` โ High-level function to generate all documentation.
- `generate_code2llm_analysis(project_path, config)` โ Convenience function to generate code2llm analysis.
- `generate_readme(project_path, output, sections, sync_markers)` โ Convenience function to generate a README.
- `analyze_and_document(project_path, config)` โ Convenience function: analyze a project in one call.
- `main()` โ code2docs โ Auto-generate project documentation from source code.
- `generate(project_path, config_path, readme_only, sections)` โ Generate documentation (default command).
- `sync(project_path, config_path, verbose, dry_run)` โ Synchronize documentation with source code changes.
- `watch(project_path, config_path, verbose)` โ Watch for file changes and auto-regenerate docs.
- `init(project_path, output)` โ Initialize code2docs.yaml configuration file.
- `check(project_path, config_path, target)` โ Health check โ verify documentation completeness.
- `diff(project_path, config_path)` โ Preview what would change without writing anything.
## Project Structure
๐ฆ `code2docs` (1 functions)
๐ `code2docs.__main__`
๐ฆ `code2docs.analyzers`
๐ `code2docs.analyzers.dependency_scanner` (6 functions, 3 classes)
๐ `code2docs.analyzers.docstring_extractor` (10 functions, 2 classes)
๐ `code2docs.analyzers.endpoint_detector` (3 functions, 2 classes)
๐ `code2docs.analyzers.project_scanner` (4 functions, 1 classes)
๐ `code2docs.base` (3 functions, 2 classes)
๐ `code2docs.cli` (14 functions, 1 classes)
๐ `code2docs.config` (5 functions, 7 classes)
๐ `code2docs.examples.advanced_usage`
๐ `code2docs.examples.quickstart`
๐ฆ `code2docs.formatters`
๐ `code2docs.formatters.badges` (2 functions)
๐ `code2docs.formatters.markdown` (13 functions, 1 classes)
๐ `code2docs.formatters.toc` (3 functions)
๐ฆ `code2docs.generators` (1 functions)
๐ `code2docs.generators._registry_adapters` (26 functions, 13 classes)
๐ `code2docs.generators._source_links` (6 functions, 1 classes)
๐ `code2docs.generators.api_changelog_gen` (9 functions, 2 classes)
๐ `code2docs.generators.api_reference_gen` (7 functions, 1 classes)
๐ `code2docs.generators.architecture_gen` (10 functions, 1 classes)
๐ `code2docs.generators.changelog_gen` (6 functions, 2 classes)
๐ `code2docs.generators.code2llm_gen` (5 functions, 1 classes)
๐ `code2docs.generators.config_docs_gen` (4 functions, 1 classes)
๐ `code2docs.generators.contributing_gen` (8 functions, 1 classes)
๐ `code2docs.generators.coverage_gen` (7 functions, 1 classes)
๐ `code2docs.generators.depgraph_gen` (9 functions, 1 classes)
๐ `code2docs.generators.examples_gen` (14 functions, 1 classes)
๐ `code2docs.generators.getting_started_gen` (8 functions, 1 classes)
๐ `code2docs.generators.mkdocs_gen` (4 functions, 1 classes)
๐ `code2docs.generators.module_docs_gen` (9 functions, 1 classes)
๐ `code2docs.generators.readme_gen` (18 functions, 1 classes)
๐ `code2docs.llm_helper` (7 functions, 1 classes)
๐ `code2docs.registry` (4 functions, 1 classes)
๐ฆ `code2docs.sync`
๐ `code2docs.sync.differ` (7 functions, 2 classes)
๐ `code2docs.sync.updater` (2 functions, 1 classes)
๐ `code2docs.sync.watcher` (1 functions)
๐ `examples.01_cli_usage` (2 functions)
๐ `examples.02_configuration` (4 functions)
๐ `examples.03_programmatic_api` (5 functions)
๐ `examples.04_sync_and_watch` (6 functions)
๐ `examples.05_custom_generators` (13 functions, 3 classes)
๐ `examples.06_formatters` (5 functions)
๐ `examples.07_web_frameworks` (5 functions)
๐ `examples.advanced_usage`
๐ `examples.basic_usage`
๐ `examples.class_examples`
๐ `examples.entry_points`
๐ `examples.quickstart`
## Requirements
- Python >= >=3.9
- code2llm >=0.5.0- jinja2 >=3.1- click >=8.0- pyyaml >=6.0- rich >=13.0
## Contributing
**Contributors:**
- Tom Softreck <tom@sapletta.com>
- Tom Sapletta <tom-sapletta-com@users.noreply.github.com>
We welcome contributions! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
# Clone the repository
git clone https://github.com/wronai/code2docs
cd code2docs
# Install in development mode
pip install -e ".[dev]"
## Documentation
- ๐ [Full Documentation](https://github.com/wronai/code2docs/tree/main/docs) โ API reference, module docs, architecture
- ๐ [Getting Started](https://github.com/wronai/code2docs/blob/main/docs/getting-started.md) โ Quick start guide
- ๐ [API Reference](https://github.com/wronai/code2docs/blob/main/docs/api.md) โ Complete API documentation
- ๐ง [Configuration](https://github.com/wronai/code2docs/blob/main/docs/configuration.md) โ Configuration options
- ๐ก [Examples](./examples) โ Usage examples and code samples
### Generated Files
| Output | Description | Link |
|--------|-------------|------|
| `README.md` | Project overview (this file) | โ |
| `docs/api.md` | Consolidated API reference | [View](./docs/api.md) |
| `docs/modules.md` | Module reference with metrics | [View](./docs/modules.md) |
| `docs/architecture.md` | Architecture with diagrams | [View](./docs/architecture.md) |
| `docs/dependency-graph.md` | Dependency graphs | [View](./docs/dependency-graph.md) |
| `docs/coverage.md` | Docstring coverage report | [View](./docs/coverage.md) |
| `docs/getting-started.md` | Getting started guide | [View](./docs/getting-started.md) |
| `docs/configuration.md` | Configuration reference | [View](./docs/configuration.md) |
| `docs/api-changelog.md` | API change tracking | [View](./docs/api-changelog.md) |
| `CONTRIBUTING.md` | Contribution guidelines | [View](./CONTRIBUTING.md) |
| `examples/` | Usage examples | [Browse](./examples) |
| `mkdocs.yml` | MkDocs configuration | โ |
<!-- code2docs:end -->
Content outside the markers is preserved when regenerating. Enable this with sync_markers: true in your configuration.
Architecture
code2docs/
โโโ registry โโโ llm_helperโโโ code2docs/ โโโ __main__ โโโ 04_sync_and_watch โโโ 05_custom_generators โโโ 06_formatters โโโ 03_programmatic_api โโโ entry_points โโโ 07_web_frameworks โโโ class_examples โโโ basic_usage โโโ 01_cli_usage โโโ 02_configuration โโโ updater โโโ sync/ โโโ watcher โโโ differ โโโ quickstart โโโ base โโโ advanced_usage โโโ badges โโโ markdown โโโ formatters/ โโโ toc โโโ coverage_gen โโโ _source_links โโโ depgraph_gen โโโ getting_started_gen โโโ config_docs_gen โโโ changelog_gen โโโ generators/ โโโ code2llm_gen โโโ module_docs_gen โโโ api_reference_gen โโโ examples_gen โโโ mkdocs_gen โโโ config โโโ api_changelog_gen โโโ _registry_adapters โโโ contributing_gen โโโ readme_gen โโโ analyzers/ โโโ docstring_extractor โโโ endpoint_detector โโโ architecture_gen โโโ project_scanner โโโ cli โโโ dependency_scanner```
## Requirements
- Python >= >=3.9
- code2llm >=0.5.0- jinja2 >=3.1- click >=8.0- pyyaml >=6.0- rich >=13.0
## Contributing
**Contributors:**
- Tom Softreck <tom@sapletta.com>
- Tom Sapletta <tom-sapletta-com@users.noreply.github.com>
We welcome contributions! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
# Clone the repository
git clone https://github.com/wronai/code2docs
cd code2docs
# Install in development mode
pip install -e ".[dev]"
## Architecture
code2docs/ โโโ cli.py # CLI (click-based) โโโ config.py # Configuration (code2docs.yaml) โโโ analyzers/ # Adapters to code2llm + custom detectors โ โโโ project_scanner.py # Wrapper on code2llm.ProjectAnalyzer โ โโโ endpoint_detector.py # Flask/FastAPI/Django route extraction โ โโโ docstring_extractor.py โ โโโ dependency_scanner.py โโโ generators/ # Documentation generators โ โโโ readme_gen.py # README.md generator โ โโโ api_reference_gen.py # docs/api/ reference from signatures โ โโโ module_docs_gen.py # docs/modules/ per-module docs โ โโโ examples_gen.py # examples/ from signatures โ โโโ changelog_gen.py # CHANGELOG from git log โ โโโ architecture_gen.py # Architecture + Mermaid diagrams โโโ templates/ # Jinja2 templates โโโ sync/ # Change detection & selective regeneration โ โโโ differ.py โ โโโ updater.py โ โโโ watcher.py โโโ formatters/ # Markdown, badges, TOC
## Requirements
- Python >= 3.9
- [code2llm](https://github.com/wronai/code2llm) >= 0.5.0
- Jinja2 >= 3.1
- Click >= 8.0
- PyYAML >= 6.0
## License
Licensed under Apache-2.0.
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 code2docs-3.0.32.tar.gz.
File metadata
- Download URL: code2docs-3.0.32.tar.gz
- Upload date:
- Size: 89.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
735da16178ac0590f529cba55cc9150586ccac9fcb0c007a849f5b63a2037ec5
|
|
| MD5 |
a8363700dbec599d2c0d4c369aa6d80b
|
|
| BLAKE2b-256 |
c7a213997e7551dbcc52f856ff48b3f2d5841b7b53e440edb4cbbce4c50edb3a
|
File details
Details for the file code2docs-3.0.32-py3-none-any.whl.
File metadata
- Download URL: code2docs-3.0.32-py3-none-any.whl
- Upload date:
- Size: 91.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4beb50b81a843078cb1c58ead4961fa76515443ea0e876e64c6cb0d8e93c2d48
|
|
| MD5 |
c35a39248a3d83194cd33a0d041fd802
|
|
| BLAKE2b-256 |
c8263f62881e9353cd439048cd5dd445a946b8e16f9bad00eb4c8c5e3c1cceb1
|