Sphinx External ToC

1.1.0 · active · verified Thu Apr 16

Sphinx External ToC is a Sphinx extension that enables a top-down approach to defining the documentation's site-map (Table of Contents) using a single YAML file, typically `_toc.yml`. This contrasts with Sphinx's default bottom-up `toctree` directives spread across multiple reStructuredText files. The library is currently at version 1.1.0 and maintains an active release cadence, providing new features and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

To quickly set up `sphinx-external-toc`, first add `sphinx_external_toc` to your `extensions` list in `conf.py`. Then, create a `_toc.yml` file in your source directory to define your documentation structure. This YAML file replaces the need for `.. toctree::` directives within your ReStructuredText or Markdown files. The `external_toc_path`, `use_multitoc_numbering`, and `external_toc_exclude_missing` options provide granular control over the ToC generation.

# conf.py (in your Sphinx project's source directory)
import os

project = 'My Docs'
copyright = '2026, My Name'
extensions = [
    'sphinx_external_toc',
    'myst_parser' # Example: if using Markdown
]

# Optional: Configure the external ToC
external_toc_path = '_toc.yml' # Default: '_toc.yml'
use_multitoc_numbering = True # Default: True, enables numbered sections
external_toc_exclude_missing = True # Default: False, prevents warnings for files not in ToC

# --- Example _toc.yml (in your Sphinx project's source directory) ---
# root: index
# chapters:
#   - file: intro
#   - file: part1
#     sections:
#       - file: part1/chapter1
#       - file: part1/chapter2
#   - file: tutorial
#   - url: https://example.com
#     title: External Link

view raw JSON →