Skip to main content

Local ToC – Sphinx extension

Sphinx Local Table of Contents Extension with Object Type Annotations and Dropdowns

This Sphinx extension enhances the local Table of Contents (ToC) by adding object type annotations (such as methods, attributes, and classes) and providing collapsible dropdowns for each object. It makes it easier for users to navigate complex documentation by categorizing and visualizing object types in a structured, interactive way.

Preview

Default local ToC with Furo

Default configurations

The image on the left shows the default configuration of this extension using the standard Furo dark theme.

Object type annotations and dropdown controls are enabled, providing a compact and navigable local Table of Contents for API-heavy pages.

Default local ToC with Furo

Customized

The image on the left shows a customized configuration of this extension using the Furo dark theme.

The title area shown above the Table of Contents is not managed by this extension.

All visual changes were made using CSS only, combined with the configuration option localtoc_dropdown_depth = 2 to increase the initial expansion depth.

Features

  • Object Type Annotations: Automatically categorizes objects in the ToC like classes, methods, attributes, etc.
  • Collapsible Dropdowns: Adds dropdown buttons next to each object type, allowing users to collapse or expand nested items.
  • Customizable: Offers view configuration variables and CSS classes to control which future and how they are displayed.

Requirements

  • Python • 3.12+
  • Sphinx • 9.1.0+
  • beautifulsoup4 • 4.14.3+

Installation

pip install sphinx-localtoc

Usage

Enable the extension

In your conf.py, add the extension to the extensions list.
Below is an example of a typical Sphinx configuration:

extensions = [
    "sphinx.ext.autodoc",           # pull in docstrings from code
    "sphinx.ext.autosummary",       # generate summary/API pages
    "sphinx.ext.napoleon",          # support Google/NumPy-style docstrings
    "sphinx.ext.intersphinx",       # link to external docs (Kivy, Python, etc.)
    "sphinx.ext.todo",              # support for exposing todo notes
    
    "sphinx_localtoc",              # stylizing the local TOC
]

Configuration options

The extension provides the following configuration variables, shown here with their default values:

# Enable or disable object type annotations in the local ToC.
localtoc_types = True

# Absolute or relative path (including filename) to a debug log file.
# If the file does not exist, it will be created.
# If it already exists, it will be overwritten.
localtoc_type_debug_file = ""

# Enable or disable the dropdown system in the local ToC.
localtoc_dropdown = True

# Number of initial ToC depth levels to skip before applying dropdown logic.
localtoc_dropdown_depth = 1

Debug file example

The debug file feature records all detected object types during the build process.

  • This feature runs only during a full build, or when the _build directory has been removed.
  • The file path is resolved relative to conf.py.
  • If the file already exists, it will be overwritten.
# Example configuration
localtoc_type_debug_file = "_static/ref/debug_ltt.txt"

The contents of the generated file depend on your project structure, but should look similar to the following:

#//|>-----------------------------------------------------------------------------------------------------------------<|
#//| Debug Local ToC report for Sphinx extension
#//| Project: KivyDK
#//| Version: 0.1.0
#//|>-----------------------------------------------------------------------------------------------------------------<|

#//|>--------------------------------------------------------<|
#//| Used CSS classes: 6
#//|>--------------------------------------------------------<|
	• slt-dropdown        | <input> items used as checkbox for dropdown system
	• slt-dropdown-branch | Starting depth branch for <ul> items
	• slt-dropdown-depth  | Nested depth branch for <ul> items
	• slt-dropdown-icon   | <label> items used for the arrows of dropdown system
	• slt-dropdown-leaf   | Last <li> items in the depth branch
	• slt-type            | Common class for all object type items


#//|>--------------------------------------------------------<|
#//| Used object type CSS classes: 7
#//|>--------------------------------------------------------<|
	• slt-obj-attribute
	• slt-obj-class
	• slt-obj-data
	• slt-obj-exception
	• slt-obj-function
	• slt-obj-method
	• slt-obj-property


#//|>--------------------------------------------------------<|
#//| One domain used
#//|>--------------------------------------------------------<|
	• py   | Python script


#//|>--------------------------------------------------------<|
#//| Used object types: 7
#//|>--------------------------------------------------------<|
	• py   | attribute
	• py   | class
	• py   | data
	• py   | exception
	• py   | function
	• py   | method
	• py   | property

License

MIT License

Copyright (c) 2026 Afanase Ioan (ASI)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Metadata

Release files for sphinx-localtoc 26.2.9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinx-localtoc 26.2.9.2
File Size Uploaded
sphinx_localtoc-26.2.9.2.tar.gz 18.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-localtoc 26.2.9.2
File Interpreter ABI Platform
sphinx_localtoc-26.2.9.2-py3-none-any.whl Python 3 none any Details

Total release size: 36.2 kB

Release files / sphinx_localtoc-26.2.9.2.tar.gz

Download URL sphinx_localtoc-26.2.9.2.tar.gz
Size 18.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2783d41f527f31bde4fbb9962b982d19b85469b520a5e7022321c89f2c3ee4d6
BLAKE2b-256 checksum
How to use checksums
3a948f8a2738b2576e0457eb7514b0b8cdb0c435792467ddbdbcedfb47eb6cd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release files / sphinx_localtoc-26.2.9.2-py3-none-any.whl

Download URL sphinx_localtoc-26.2.9.2-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90b466591bdebb73c30ad914f7868a622a710dde1fb247a8a94e05257eaf7f87
BLAKE2b-256 checksum
How to use checksums
f7fb9e4f897bfa04857acb1712f21888c8263c6724ed0a1fb94c13d28fd8350f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

26.2.9.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page