Sphinx PlantUML Extension
sphinxcontrib-plantuml is a Sphinx extension that enables the embedding of PlantUML diagrams directly into reStructuredText or Markdown documentation. It translates PlantUML text blocks into image files (PNG, SVG, PDF) during the Sphinx build process. The current version is 0.31, and the project maintains a fairly active release cadence, with multiple updates in recent years.
Warnings
- breaking The `sphinxcontrib-plantuml` extension itself is merely a Python wrapper for Sphinx. It *requires* PlantUML (the Java application) and a Java Runtime Environment (JRE) to be installed separately on the system where Sphinx builds are performed. Without these, diagrams cannot be rendered, leading to build failures or 'unknown directive' errors.
- gotcha If the `plantuml` command is not in your system's PATH, you must explicitly configure its full command in `conf.py`. Failing to do so will result in Sphinx being unable to find and execute PlantUML.
- gotcha PlantUML can sometimes silently fall back to generating PNG images, even when another format (like SVG) is requested, for example, when certain diagram types (e.g., ditaa) are included. This silent fallback can cause unexpected encoding errors in `sphinxcontrib-plantuml` if it expects a specific output format.
- gotcha For HTML output, the default `plantuml_output_format` is `png`. If using SVG, `svg_obj` (embedding with `<object/>`) might lead to scaling issues in some browsers. For better responsiveness, `svg_img` (embedding with `<img/>`) is often preferred. For LaTeX/PDF output, `png` quality can be poor; `svg_pdf` (requires `sphinxcontrib-svg2pdfconverter` or similar) or `eps_pdf` (requires `epstopdf`) is recommended.
- deprecated Older versions of `sphinxcontrib-plantuml` had compatibility issues with newer Sphinx 4.x releases and Python 3.13 due to internal API changes in Sphinx and Python's `inspect` module.
Install
-
pip install sphinxcontrib-plantuml
Imports
- sphinxcontrib.plantuml
extensions = ['sphinxcontrib.plantuml']
Quickstart
# conf.py
import os
project = 'My Project'
copyright = '2026, Your Name'
extensions = [
'sphinxcontrib.plantuml',
]
# Configure PlantUML executable path (essential if not in PATH)
# Replace '/path/to/plantuml.jar' with the actual path.
# If 'plantuml' command is in your system PATH, this line can be omitted.
# plantuml = 'java -jar /path/to/plantuml.jar'
# Optional: Set output format (default is 'png' for HTML)
# plantuml_output_format = 'svg_img'
# index.rst (or a new .rst file)
# Add the following to your .rst file:
# .. uml::
# @startuml
# Alice -> Bob: Hello
# Bob -> Alice: Hi!
# @enduml
# To build the documentation:
# sphinx-build -b html . _build/html