Installation and usage

Installation

sphinx-structured-toc is available on PyPI. Install it with pip:

pip install sphinx-structured-toc

or with uv:

uv add sphinx-structured-toc

The extension requires Python 3.10 or later, Sphinx 7.x, and docutils 0.21.2 or later.

Add sphinx_structured_toc to the extensions list in conf.py:

extensions = ["sphinx_structured_toc"]

No other configuration is required. The extension ships a small CSS file that is automatically copied into your build’s _static directory and linked from every page.

A minimal example

A domain contains one or more slice blocks. Each slice contains one or more :doc: item lines, one per line:

The model layer
~~~~~~~~~~~~~~~

..  domain::

    ..  slice:: Models

        :doc:`Field types <demo-targets/field-types-reference>`
        :doc:`Custom fields <demo-targets/custom-fields-how-to>`

    ..  slice:: Queries

        :doc:`Lookup expressions <demo-targets/lookup-expressions-how-to>`
        :doc:`Queryset operations <demo-targets/queryset-operations-how-to>`

This renders as a single <nav> representing the domain. It contains one list of two slices.

Each slice begins with its name, followed by a list of links with CSS separators:

The struture of each domain is a nested list:

ul: the domain
    li: the slice
        ul:
            li: link
            li: link

Ambiguity warnings

The extension emits a warning for link names that collide. This can be suppressed per particular domain with :suppress-warnings: flag:

..  domain::
    :suppress-warnings: