sphinx-substitution-extensions 2026.1.12


pip install sphinx-substitution-extensions

  Latest version

Released: Jan 12, 2026

Project Links

Meta
Author: Adam Dangoor
Requires Python: >=3.10

Classifiers

Development Status
  • 5 - Production/Stable

Environment
  • Web Environment

Framework
  • Pytest

Operating System
  • Microsoft :: Windows
  • POSIX

Programming Language
  • Python :: 3 :: Only
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13

Build Status PyPI

Sphinx Substitution Extensions

Extensions for Sphinx which allow substitutions within code blocks.

Installation

Sphinx Substitution Extensions is compatible with Sphinx 8.2.0+ using Python 3.10+.

$ pip install Sphinx-Substitution-Extensions

rST setup

  1. Add the following to conf.py to enable the extension:

"""Configuration for Sphinx."""

extensions = ["sphinxcontrib.spelling"]  # Example existing extensions

extensions += ["sphinx_substitution_extensions"]
  1. Set the following variable in conf.py to define substitutions:

"""Configuration for Sphinx."""

rst_prolog = """
.. |release| replace:: 0.1
.. |author| replace:: Eleanor
"""

This will replace |release| in the new directives with 0.1, and |author| with Eleanor.

Using substitutions in rST documents

code-block

This adds a :substitutions: option to Sphinx’s built-in code-block directive.

.. code-block:: shell
   :substitutions:

   echo "|author| released version |release|"

Inline :substitution-code:

:substitution-code:`echo "|author| released version |release|"`

substitution-download

:substitution-download:`|author|'s manuscript <|author|_manuscript.txt>`

literalinclude

This adds :content-substitutions: and :path-substitutions: options to Sphinx’s built-in literalinclude directive.

Replace substitutions in the content of the included file:

.. literalinclude:: path/to/file.txt
   :content-substitutions:

Replace substitutions in the file path:

.. literalinclude:: path/to/|author|_file.txt
   :path-substitutions:

image

This adds a :path-substitutions: option to Sphinx’s built-in image directive.

Replace substitutions in the image path:

.. image:: path/to/|author|_diagram.png
   :path-substitutions:
   :alt: Diagram

MyST Markdown setup

  1. Add sphinx_substitution_extensions to extensions in conf.py to enable the extension:

"""Configuration for Sphinx."""

extensions = ["myst_parser"]  # Example existing extensions

extensions += ["sphinx_substitution_extensions"]
  1. Set the following variables in conf.py to define substitutions:

"""Configuration for Sphinx."""

myst_enable_extensions = ["substitution"]

myst_substitutions = {
    "release": "0.1",
    "author": "Eleanor",
}

This will replace |release| in the new directives with 0.1, and |author| with Eleanor.

Enabling substitutions by default

By default, you need to explicitly add the :substitutions: flag to code-block directives, and :content-substitutions: or :path-substitutions: flags to literalinclude directives.

If you want substitutions to be applied by default without needing these flags, you can set the following in conf.py:

"""Configuration for Sphinx."""

substitutions_default_enabled = True

When this is enabled:

  • All code-block directives will have substitutions applied automatically

  • All literalinclude directives will have both content and path substitutions applied automatically

You can disable substitutions for specific directives when the default is enabled:

.. code-block:: shell
   :nosubstitutions:

   echo "This |will| not be substituted"

.. literalinclude:: path/to/file.txt
   :nocontent-substitutions:

.. literalinclude:: path/to/|literal|_file.txt
   :nopath-substitutions:

Using substitutions in MyST Markdown

code-block

This adds a :substitutions: option to Sphinx’s built-in code-block directive.

```{code-block} bash
   :substitutions:

   echo "|author| released version |release|"
```

As well as using |author|, you can also use {{author}}. This will respect the value of myst_sub_delimiters as set in conf.py.

Inline :substitution-code:

{substitution-code}`echo "|author| released version |release|"`

substitution-download

{substitution-download}`|author|'s manuscript <|author|_manuscript.txt>`

literalinclude

This adds :content-substitutions: and :path-substitutions: options to Sphinx’s built-in literalinclude directive.

Replace substitutions in the content of the included file:

```{literalinclude} path/to/file.txt
   :content-substitutions:
```

Replace substitutions in the file path:

```{literalinclude} path/to/|author|_file.txt
   :path-substitutions:
```

image

This adds a :path-substitutions: option to Sphinx’s built-in image directive.

Replace substitutions in the image path:

```{image} path/to/|author|_diagram.png
   :path-substitutions:
   :alt: Diagram
```

Credits

ClusterHQ Developers

This package is largely inspired by code written for Flocker by ClusterHQ. Developers of the relevant code include, at least, Jon Giddy and Tom Prince.

Contributing

See CONTRIBUTING.rst.

2026.1.12 Jan 12, 2026
2025.12.15 Dec 15, 2025
2025.11.17 Nov 17, 2025
2025.10.24 Oct 24, 2025
2025.6.6 Jun 06, 2025
2025.4.3 Apr 03, 2025
2025.3.3 Mar 03, 2025
2025.2.19 Feb 19, 2025
2025.1.2 Jan 02, 2025
2024.10.17 Oct 17, 2024
2024.8.6 Aug 06, 2024
2024.2.25 Feb 25, 2024
2024.2.24.1 Feb 24, 2024
2024.2.24 Feb 24, 2024
2022.2.16 Feb 16, 2022
2020.9.30.0 Sep 30, 2020
2020.7.4.1 Jul 04, 2020
2020.7.4.0 Jul 04, 2020
2020.5.30.0 May 30, 2020
2020.5.27.0 May 27, 2020
2020.5.23.0 May 23, 2020
2020.4.5.0 Apr 05, 2020
2020.2.21.0 Feb 21, 2020
2019.12.28.0 Dec 28, 2019
2019.6.15.0 Jun 15, 2019
2019.4.4.1 Apr 04, 2019
2018.11.12.3 Nov 12, 2018
2018.11.12.2 Nov 12, 2018
2018.11.12.1 Nov 12, 2018
Sphinx Substitution Extensions-2022.2.16.tar.gz Feb 16, 2022
Sphinx Substitution Extensions-2020.9.30.0.tar.gz Sep 30, 2020
Sphinx Substitution Extensions-2020.7.4.1.tar.gz Jul 04, 2020
Sphinx Substitution Extensions-2020.7.4.0.tar.gz Jul 04, 2020
Sphinx Substitution Extensions-2020.5.30.0.tar.gz May 30, 2020
Sphinx Substitution Extensions-2020.5.27.0.tar.gz May 27, 2020
Sphinx Substitution Extensions-2020.5.23.0.tar.gz May 23, 2020
Sphinx Substitution Extensions-2020.4.5.0.tar.gz Apr 05, 2020
Sphinx Substitution Extensions-2020.2.21.0.tar.gz Feb 21, 2020
Sphinx Substitution Extensions-2019.6.15.0.tar.gz Jun 15, 2019
Sphinx Substitution Extensions-2019.4.4.1.tar.gz Apr 04, 2019
Sphinx Substitution Extensions-2019.12.28.0.tar.gz Dec 28, 2019
Sphinx Substitution Extensions-2018.11.12.3.tar.gz Nov 12, 2018
Sphinx Substitution Extensions-2018.11.12.2.tar.gz Nov 12, 2018
Sphinx Substitution Extensions-2018.11.12.1.tar.gz Nov 12, 2018
Extras:
Dependencies:
beartype (>=0.22.9)
docutils (>=0.19)
myst-parser (>=4.0.0)
sphinx (>=8.1.0)