Sphinxcontrib-redoc

1.6.0 · maintenance · verified Sat Apr 11

Sphinxcontrib-redoc is a Sphinx extension that renders OpenAPI (formerly Swagger) specifications using the ReDoc library. It integrates interactive API documentation directly into Sphinx-generated documentation. The current version is 1.6.0, released in April 2020, indicating that the project is in a maintenance state with infrequent updates.

Warnings

Install

Imports

Quickstart

To quickly integrate sphinxcontrib-redoc, first install the package. Then, enable the extension by adding 'sphinxcontrib.redoc' to the `extensions` list in your Sphinx `conf.py`. Define your OpenAPI specifications using the `redoc` configuration variable, which is a list of dictionaries. Each dictionary specifies the API's name, the output HTML page path, the path (local or URL) to the OpenAPI spec, and optional ReDoc rendering options. You must also create an RST file (e.g., `api/index.rst`) for each defined page to ensure it's included in Sphinx's table of contents and provides a target for the rendered documentation.

# conf.py
import os

project = 'My API Docs'
copyright = '2026, Your Name'
extensions = [
    'sphinxcontrib.redoc',
    'sphinx.ext.autodoc', # Example of another common extension
]

# Configure sphinxcontrib-redoc
redoc = [
    {
        'name': 'My Awesome API',
        'page': 'api/index', # Output HTML page path relative to build directory
        'spec': 'openapi.yaml', # Path to OpenAPI spec relative to conf.py
        'embed': True, # Embed the spec into the HTML page
        'opts': {
            'lazy-rendering': True,
            'native-scrollbars': True,
            'hide-hostname': True,
            'expand-responses': ['200', '201'],
        }
    },
]

# Example of a minimal index.rst or api/index.rst
# My Awesome API
# ==============
#
# .. toctree::
#    :maxdepth: 2
#
# .. raw:: html
#
#    <div id="redoc-container"></div>

# Make sure the openapi.yaml exists in your docs folder for a local spec.
# Or use a remote URL: 'spec': 'https://petstore.swagger.io/v2/swagger.json'

view raw JSON →