Documentation Overview
CPython documentation is located in theDoc/ directory and includes:
- Library reference: Standard library documentation
- Language reference: Python language specification
- C API reference: CPython C API documentation
- Tutorials: Getting started guides
- How-tos: Task-focused guides
- FAQs: Frequently asked questions
You don’t need to build documentation yourself - prebuilt versions are available.
Setting Up Documentation Build
Install Dependencies
Create virtual environment
Doc/venv with all necessary tools:- Sphinx: Documentation builder
- blurb: News entry tool
- python-docs-theme: Python documentation theme
Doc/build/html/.
You can specify a custom virtual environment location with
VENVDIR:Alternative: Without make
If you can’t use make:Building Documentation
Available Build Targets
Windows Build
On Windows, usemake.bat:
PYTHON environment variable if needed:
reStructuredText Basics
CPython documentation uses reStructuredText (reST) markup.Headings
Paragraphs and Text Formatting
Code Blocks
Links
Lists
Admonitions
Documenting Python Code
Module Documentation
Create or edit files inDoc/library/:
Function Documentation
Class Documentation
Documenting C API
C Function Documentation
InDoc/c-api/*.rst:
C Type Documentation
Adding News Entries
For significant changes, add a news entry usingblurb:
News entries are categorized by type:
Core and Builtins: Interpreter coreLibrary: Standard libraryDocumentation: Documentation changesTests: Test suite changesBuild: Build system changesWindows: Windows-specific changesmacOS: macOS-specific changesIDLE: IDLE changesTools-Demos: Tools and demosC API: C API changes
Documentation Style Guide
Voice and Tone
- Use active voice: “Returns a list” not “A list is returned”
- Be concise but complete
- Use present tense: “Creates” not “Will create”
- Address the reader as “you” when appropriate
Technical Style
Parameter Documentation
Examples
Include examples when helpful:Checking Your Documentation
Syntax Check
- Syntax errors
- Broken references
- Formatting issues
Link Check
Build and Review
Contributing Documentation
Documentation-Only Changes
Documentation with Code Changes
When adding features:- Update the relevant
.rstfile - Add docstrings to the code
- Include examples if helpful
- Add a news entry with
blurb
Troubleshooting
Sphinx build errors
Sphinx build errors
Common issues:
Missing dependencies
Missing dependencies
Reinstall documentation tools:
Broken cross-references
Broken cross-references
Use the correct role:
blurb not found
blurb not found
Install blurb:
Best Practices
- Keep it simple: Use clear, straightforward language
- Show examples: Include code examples when helpful
- Link generously: Cross-reference related functions
- Update thoroughly: Update all affected docs
- Test the docs: Build and review HTML output
- Follow style: Match existing documentation style
- Spell check: Use a spell checker
Next Steps
- Browse Python Documentation
- Read Documenting Python Guide
- Study Sphinx Documentation
- Review reStructuredText Primer
