Sphinx-Gallery
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
- breaking Support for Python 3.8 has been dropped. Sphinx-Gallery now requires Python >=3.10.
- breaking Support for Python 3.8 and Sphinx 4 has been dropped. Sphinx-Gallery now requires Python >=3.9 and Sphinx >=5.
- breaking Due to Sphinx 7.3.0+ caching changes, certain `sphinx_gallery_conf` options that accept callables (e.g., `reset_argv`, `FileNameSortKey`, `notebook_modification_function`) must now be provided as fully qualified name *strings* (e.g., `'path.to.my_function'`) instead of instantiated classes or direct callables. Passing objects with unstable `__repr__` can force unnecessary rebuilds.
- breaking Support for Python 3.7 was dropped. Additionally, `Pillow` was added as a required dependency.
Install
-
pip install sphinx-gallery
Imports
- sphinx_gallery.gen_gallery
extensions = ['sphinx_gallery.gen_gallery']
Quickstart
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
}