Sphinx-Gallery

0.20.0 · active · verified Sun Apr 12

Sphinx-Gallery is a Sphinx extension that automatically generates an HTML gallery of examples from any set of Python scripts. It converts `.py` files into reStructuredText, Jupyter notebooks, and includes features like thumbnail generation and API back-references. It is actively maintained with frequent releases, currently at version 0.20.0.

Warnings

Install

Imports

Quickstart

To integrate Sphinx-Gallery, first enable it by adding `'sphinx_gallery.gen_gallery'` to the `extensions` list in your Sphinx `conf.py` file. Then, define the `sphinx_gallery_conf` dictionary to specify the input directory for your example scripts (`examples_dirs`) and the output directory for the generated gallery (`gallery_dirs`). The paths should be relative to `conf.py`.

import os

# conf.py example
extensions = [
    # ... other extensions
    'sphinx_gallery.gen_gallery',
]

# Path to the directory containing example scripts, relative to conf.py
examples_dir = os.path.join(os.path.dirname(__file__), '../examples')

# Path to where Sphinx-Gallery should save its generated output, relative to conf.py
gallery_dir = 'auto_examples'

sphinx_gallery_conf = {
    'examples_dirs': examples_dir,
    'gallery_dirs': gallery_dir,
    'plot_gallery': 'True', # Set to False to disable example execution
    'backreferences_dir': 'gen_modules/backreferences' # For mini-galleries
}

view raw JSON →