PyCodeCommenter — Python Docstring Generator & Validator¶
Keep Python docstrings accurate as your code evolves.
Deterministic docstring generation and validation for production Python. No AI guesswork by default — just reliable, rule-based inference that syncs your docs with your AST. AI drafting is opt-in.
What is PyCodeCommenter?¶
PyCodeCommenter is an open-source Python tool that:
- Writes docstrings from what your code proves — names, types, defaults, raise conditions, boolean checks — keeping anything you already wrote (including a
#comment above the function) and marking what only a person can say. - Drafts the rest with AI, if you opt in (
--ai-draft), labelling every drafted line(AI-drafted, unreviewed)— thenpycodecommenter reviewlets you accept, edit or skip each one. - Validates existing docstrings against real function signatures across six check categories.
- Measures documentation coverage per file and across entire projects, with JSON output for CI.
Install with: pip install pycodecommenter · Requires Python 3.10+
The Problem & The Solution¶
Before PyCodeCommenter: Code changes, but docstrings don't.
After PyCodeCommenter: Run $ pycodecommenter generate <path/to/your_file.py> to sync the skeleton — names, types and defaults, always accurate because they're extracted, not guessed. What the tool can't extract (what process_data actually means) is left as an explicit TODO(pycodecommenter): describe marker, not a guessed sentence (real output):
def process_data(items, strict=False):
"""Process data.
Args:
items (Any): TODO(pycodecommenter): describe.
strict (Any): TODO(pycodecommenter): describe. (default: False)
Returns:
Any: TODO(pycodecommenter): describe
"""
return items
Add --ai-draft to have those gaps drafted (each line labelled (AI-drafted, unreviewed)), then pycodecommenter review to accept, edit or skip each drafted line.
1. Install¶
2. Run¶
Preview the changes PyCodeCommenter will make to your project without writing to disk:
Ready to apply? Write docstrings directly into the file:
Validate and get a JSON report:
3. Explore the Documentation¶
Key Facts¶
| Property | Value |
|---|---|
| PyPI package | pycodecommenter |
| Import name | PyCodeCommenter |
| Python support | 3.10, 3.11, 3.12, 3.13 |
| Output docstring style | Google for new docstrings; existing NumPy/Sphinx docstrings keep their style |
| Input parsing | Google (full), Sphinx (full), NumPy (full) |
| AI / LLM dependency | None by default (deterministic); optional --ai-draft via a free hosted service or your own Gemini/OpenAI/Anthropic/DeepSeek key |
| Runtime dependencies | ruamel.yaml (config), libcst (patching) |
| License | MIT |
| Version | 2.6.1 |
Links¶
- PyPI: pypi.org/project/pycodecommenter
- GitHub: github.com/AmosQuety/PyCodeCommenter
- Issues: github.com/AmosQuety/PyCodeCommenter/issues
- Creator: Nabasa Amos (Amos Quety)