sphinx-pyproject

0.3.0 · active · verified Thu Apr 16

sphinx-pyproject is a Python library that enables you to move parts of your Sphinx documentation configuration into your `pyproject.toml` file, promoting a centralized project configuration. The current version is 0.3.0, released in August 2023. While releases are infrequent, the project remains actively maintained.

Common errors

Warnings

Install

Imports

Quickstart

To integrate `sphinx-pyproject` with your Sphinx project, first define your project's metadata and Sphinx-specific configurations in your `pyproject.toml` file under the `[project]` and `[tool.sphinx-pyproject]` tables. Then, in your `conf.py` file, import `SphinxConfig` and instantiate it, passing the path to your `pyproject.toml` and `globalns=globals()` to make the configuration values available in the `conf.py` namespace.

# pyproject.toml
[project]
name = "my-awesome-project"
version = "0.1.0"
description = "My awesome project description."
authors = [{name = "Your Name", email = "you@example.com"}]

[tool.sphinx-pyproject]
project = "My Awesome Project Docs"
copyright = "2026, Your Name"
extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.napoleon"
]
html_theme = "furo"

# conf.py
import os
import sys
sys.path.insert(0, os.path.abspath('.')) # Adjust this path to your project root if needed

from sphinx_pyproject import SphinxConfig

# Load configuration from pyproject.toml and make variables available globally in conf.py
config = SphinxConfig("../pyproject.toml", globalns=globals())

# You can also access values directly from the config object:
# project_name = config["project"]
# print(project_name)

# If globalns=globals() is used, you can access directly:
# print(project)
# print(copyright)

view raw JSON →