Skip to main content
CPython’s documentation is written in reStructuredText and built with Sphinx. This guide covers how to build, edit, and contribute to the documentation.

Documentation Overview

CPython documentation is located in the Doc/ 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

1

Navigate to Doc directory

2

Create virtual environment

This creates a virtual environment in Doc/venv with all necessary tools:
  • Sphinx: Documentation builder
  • blurb: News entry tool
  • python-docs-theme: Python documentation theme
3

Build HTML documentation

The built documentation will be in 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, use make.bat:
Set the PYTHON environment variable if needed:

reStructuredText Basics

CPython documentation uses reStructuredText (reST) markup.

Headings

Paragraphs and Text Formatting

Code Blocks

Lists

Admonitions

Documenting Python Code

Module Documentation

Create or edit files in Doc/library/:

Function Documentation

Class Documentation

Documenting C API

C Function Documentation

In Doc/c-api/*.rst:

C Type Documentation

Adding News Entries

For significant changes, add a news entry using blurb:
1

Create news entry

This opens your editor to write the news entry.
2

Write the entry

Describe the change clearly and concisely:
3

Save and commit

The entry is saved to Misc/NEWS.d/next/. Commit it with your changes:
News entries are categorized by type:
  • Core and Builtins: Interpreter core
  • Library: Standard library
  • Documentation: Documentation changes
  • Tests: Test suite changes
  • Build: Build system changes
  • Windows: Windows-specific changes
  • macOS: macOS-specific changes
  • IDLE: IDLE changes
  • Tools-Demos: Tools and demos
  • C 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

This checks for:
  • Syntax errors
  • Broken references
  • Formatting issues
This verifies all external links are valid.

Build and Review

Contributing Documentation

Documentation-Only Changes

1

Create a branch

2

Edit documentation

3

Build and review

4

Commit and push

Documentation with Code Changes

When adding features:
  1. Update the relevant .rst file
  2. Add docstrings to the code
  3. Include examples if helpful
  4. Add a news entry with blurb

Troubleshooting

Common issues:
Reinstall documentation tools:
Use the correct role:
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

Additional Resources