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.
pip install sphinx-pyprojectVerified import paths — ran on the pinned version, not inferred.
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.
Initialize SphinxConfig with `style="poetry"` for Poetry-managed projects.
Add `globalns=globals()` to the `SphinxConfig` instantiation, or explicitly retrieve values via `config['key']`.
Review your `SphinxConfig` instantiation if upgrading from very old versions to ensure compatibility with new arguments, particularly if using positional arguments or relying on default behavior for `style`.
Install the package: `pip install sphinx-pyproject`
Ensure the key exists and is correctly spelled under the `[tool.sphinx-pyproject]` table in your `pyproject.toml`. For example: `[tool.sphinx-pyproject] my_config_key = "value"`
Modify your `SphinxConfig` instantiation to `config = SphinxConfig("../pyproject.toml", globalns=globals())`. Alternatively, access the values directly from the `config` object: `project_name = config["project"]`.