Sphinxcontrib-redoc
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
- breaking Version 1.6.0 dropped official support for Python 3.4. Ensure you are using Python 3.5 or newer.
- gotcha ReDoc can experience performance issues when rendering very large or complex OpenAPI specifications, leading to slow page load times in the generated documentation.
- gotcha When `embed` is set to `True`, the extension currently does not support embedding OpenAPI specifications from external HTTP(s) links; only local file paths are supported for embedding.
- gotcha As of Sphinx 8, subsequent builds may produce a `WARNING: Aborted attempted copy from ... redoc.js` message. While often harmless, it can clutter build logs.
- gotcha The `redoc.js` library bundled with `sphinxcontrib-redoc` (last updated with v1.21.2 in 1.4.0, with minor updates up to 1.6.0) is potentially outdated. Newer ReDoc versions offer better features and bug fixes.
- gotcha The HTML page generated by `sphinxcontrib-redoc` is not automatically included in Sphinx's `toctree` (table of contents).
Install
-
pip install sphinxcontrib-redoc
Imports
- sphinxcontrib.redoc
extensions = ['sphinxcontrib.redoc']
Quickstart
# 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'