skillfed

sphinx-gallery

A Sphinx extension that builds an HTML gallery of examples from any set of Python scripts.

sphinx-gallery v0.21.0 650.8K downloads/30d#5,556 on PyPI454
Permissive license 3-clause BSD Active released

What it is and what it does

Sphinx-Gallery is a Sphinx extension that transforms a directory of Python example scripts into an interactive HTML gallery embedded in your documentation. It executes each script, captures outputs (including plots from Matplotlib and related packages), and generates formatted gallery pages with the code, results, and narrative text from docstrings or accompanying README files.

You configure it in your Sphinx conf.py by specifying the source directory of example scripts and the output directory for generated gallery files. Sphinx-Gallery then handles execution, output capture, and reST file generation during your normal Sphinx build. It's designed for library documentation but can also serve as a standalone showcase for a Python package or module.

Use it for:

  • Build an interactive example gallery for a scientific Python library (like scikit-learn or Matplotlib) to demonstrate typical usage patterns.
  • Generate a gallery of tutorials or how-to guides from executable Python scripts as part of your project documentation.
  • Showcase data analysis workflows or computational examples with live output and visualizations in a web-accessible format.
  • Create a portfolio or cookbook of example code snippets with their results for educational or reference purposes.
  • Automatically keep example outputs in sync with code changes by re-executing scripts during documentation builds.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Sphinx-Gallery is a Sphinx extension that automatically generates HTML galleries of executable examples from Python scripts, extracting outputs and embedding them into your documentation.

Yes. Sphinx-Gallery is a mature, actively maintained tool with low install friction and no known vulnerabilities. It solves a concrete problem—turning Python scripts into documented, executable galleries—and is widely adopted by major projects. Install it if you need to showcase runnable examples in Sphinx documentation.

Install

sphinx-gallery on PyPI

pip

pip install sphinx-gallery

uv

uv add sphinx-gallery

poetry

poetry add sphinx-gallery

Installing sphinx-gallery

Before you install

Low friction: pure Python wheel with only two runtime dependencies (pillow and sphinx). Actively maintained as of 2026-04-24 with recent activity, supporting current Python versions (3.10–3.14).

License in practice

3-clause BSD is permissive; you can use, modify, and distribute sphinx-gallery freely in commercial and private projects with minimal restrictions.

Quickstart

pip install sphinx-gallery

# In doc/conf.py:
extensions = ['sphinx_gallery.gen_gallery']
sphinx_gallery_conf = {
    'examples_dirs': '../examples',
    'gallery_dirs': 'auto_examples',
}

Requires Sphinx and pillow as runtime dependencies; Python 3.10 or later.

Verify before relying

  • Whether optional system binaries (optipng) are required or merely recommended for PNG optimization.
  • Performance characteristics when processing large numbers of example scripts or high-resolution images.

Package facts

License 3-clause BSD (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 2 — pillow, sphinx
Maintenance actively maintained — 112 days since the last release
Last repo commit
First released
Downloads 650,798/month — #5,556 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: sphinx_gallery-0.21.0-py3-none-any.whl

Development Status :: 4 - BetaFramework :: Sphinx :: ExtensionIntended Audience :: DevelopersProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14

Tags

sphinx documentation gallery generatorpython example gallery buildersphinx extension example showcaseauto-generate documentation examplesexecutable python script gallerysphinx gallery from python filesdocumentation example runner
documentation-generationsphinx-extensionexample-gallery

More Sphinx packages

docstring-parser

Parses Python docstrings in ReST, Google,…

permissive · top 1,000 on PyPI

Sphinx

Sphinx generates professional documentation…

permissive · top 1,000 on PyPI

sphinxcontrib-serializinghtml

A Sphinx extension that outputs documentation…

permissive · top 1,000 on PyPI

alabaster

Alabaster is a clean, responsive Sphinx theme…

permissive · top 1,000 on PyPI

sphinxcontrib-htmlhelp

A Sphinx extension that generates HTML help…

permissive · top 1,000 on PyPI

sphinxcontrib-qthelp

A Sphinx extension that converts documentation…

permissive · top 1,000 on PyPI

sphinx-click

Sphinx-click is a Sphinx extension that…

permissive · top 15,000 on PyPI

sphinx-jinja

A Sphinx extension that lets you embed Jinja2…

permissive · top 5,000 on PyPI

sphinx-tabs

A Sphinx extension that adds tabbed content…

permissive · top 5,000 on PyPI

sphinx-markdown-builder

A Sphinx extension that generates Markdown…

permissive · top 15,000 on PyPI

autodocsumm

A Sphinx extension that enhances autodoc with…

permissive · top 5,000 on PyPI

sphinx-favicon

A Sphinx extension that injects custom favicon…

permissive · top 15,000 on PyPI

sphinx-markdown-tables

Adds markdown table support to Sphinx…

copyleft · top 15,000 on PyPI

sphinx-llm

Sphinx extensions that generate LLM-consumable…

permissive · top 15,000 on PyPI

nbsphinx

nbsphinx is a Sphinx extension that parses…

permissive · top 5,000 on PyPI

sphinxcontrib-django

A Sphinx extension that enhances autodoc output…

permissive · top 15,000 on PyPI