Sphinx: Python Documentation Generator
Sphinx is a documentation generator that produces HTML, PDF, ePub, and other formats from source files written in reStructuredText or Markdown. It powers the official Python documentation and is the default documentation tool across most of the scientific Python ecosystem.
Note
Sphinx 9.1.0 was released on December 31, 2025 and is licensed BSD-2-Clause. Install via uv add --group docs sphinx or pip install sphinx.
When to use Sphinx
Pick Sphinx when the documentation is API-first (most pages are autogenerated from docstrings), when contributors are comfortable with reStructuredText, or when the project benefits from the broader cross-reference and extension ecosystem (intersphinx for cross-project links, sphinx-autodoc-typehints for signature rendering). Sphinx is the established default for CPython, NumPy, SciPy, scikit-learn, pandas, Django, and Flask. For a comparison with the Markdown-first alternative, see the MkDocs reference.
Key Features
- Reads reStructuredText (
.rst) by default; reads Markdown (.md) through the MyST extension - Automatic API documentation from Python source via
sphinx.ext.autodoc - Cross-project references via
sphinx.ext.intersphinx(link from your docs to CPython, NumPy, requests, and any other Sphinx-built site) - Multiple output builders out of the box: HTML, LaTeX (for PDF), ePub, Texinfo, manual pages, JSON, plain text
- Theme ecosystem: built-in
alabaster, plus third-party themes like Furo and the Read the Docs theme - Extension API used by hundreds of third-party packages
Built-in Extensions
Sphinx ships with several extensions that most projects enable in conf.py:
| Extension | Purpose |
|---|---|
sphinx.ext.autodoc |
Import a module and render its docstrings |
sphinx.ext.napoleon |
Parse Google-style and NumPy-style docstrings |
sphinx.ext.intersphinx |
Link to other Sphinx sites by reference |
sphinx.ext.viewcode |
Add a “[source]” link from each documented object to its source |
sphinx.ext.doctest |
Run interactive doctest snippets as part of the build |
sphinx.ext.todo |
Collect .. todo:: directives into a project-wide list |
Configuration
A Sphinx site lives in a docs directory with a conf.py file (Python configuration), a top-level index.rst (the table of contents), and one or more source files. sphinx-quickstart scaffolds the directory.
project = "mypackage"
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
]
html_theme = "furo"Build the HTML output with sphinx-build:
sphinx-build -b html docs/source docs/build/htmlFor an iterative authoring loop, use sphinx-autobuild instead, which watches the source tree and refreshes the browser on change.
Pros
- Long track record (first release 2008)
- Largest extension ecosystem of any Python doc tool
- Multiple output formats from a single source tree
- Standard choice in scientific Python and CPython itself
- Cross-references work across projects via
intersphinx
Cons
- reStructuredText has a steeper learning curve than Markdown for new contributors
- Configuration via executable Python
conf.pyis more flexible but harder to reason about than a static YAML file - Default
alabastertheme looks dated; most projects switch to Furo or the Read the Docs theme - MyST closes the Markdown gap but does not eliminate the reStructuredText assumptions in third-party extensions