Sphinx Napoleon Extension

0.7 · maintenance · verified Tue Apr 14

Sphinxcontrib-napoleon is a Sphinx extension that acts as a pre-processor, enabling Sphinx to parse and convert both NumPy and Google style docstrings into reStructuredText. This allows developers to write more legible and less verbose docstrings in their Python code. The standalone `sphinxcontrib-napoleon` package is currently at version 0.7, with its last release in 2018. While this package is maintained for compatibility with older Sphinx versions (<=1.2), its core functionality has been integrated directly into Sphinx as `sphinx.ext.napoleon` since Sphinx 1.3, making the `sphinx.ext.napoleon` path the modern standard for newer Sphinx projects.

Warnings

Install

Imports

Quickstart

To quickly integrate Napoleon, install the package, then enable it in your Sphinx project's `conf.py` by adding `'sphinx.ext.napoleon'` (or `'sphinxcontrib.napoleon'` for older Sphinx versions) to the `extensions` list. Ensure `sphinx.ext.autodoc` is also enabled. After configuration, use `sphinx-apidoc` to generate RST files from your Python source and then `make html` (or `sphinx-build`) to build the documentation.

# 1. Install sphinxcontrib-napoleon (if using Sphinx <= 1.2, or for older projects)
# pip install sphinxcontrib-napoleon

# 2. In your Sphinx project's conf.py file:
import os
import sys
sys.path.insert(0, os.path.abspath('.'))

# Add 'sphinx.ext.autodoc' to ensure docstrings are processed
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon' # Use 'sphinxcontrib.napoleon' for Sphinx <= 1.2
]

# Optional: Configure napoleon settings (defaults shown)
napoleon_google_docstring = True
napoleon_numpy_docstring = True
napoleon_include_init_with_doc = False
napoleon_include_private_with_doc = False
napoleon_include_special_with_doc = False
napoleon_use_admonition_for_examples = False
napoleon_use_admonition_for_notes = False
napoleon_use_admonition_for_references = False
napoleon_use_ivar = False
napoleon_use_param = True
napoleon_use_rtype = True
napoleon_use_keyword = True
napoleon_custom_sections = None

# 3. Generate API documentation (run from your project root or docs directory):
# sphinx-apidoc -f -o docs/source your_project_module_path
# make html (or sphinx-build -b html docs/source docs/build/html)

view raw JSON →