Jupyter Notebook Tools for Sphinx

0.9.8 · active · verified Sat Apr 11

nbsphinx is a Sphinx extension that provides a source parser for *.ipynb files. It allows Sphinx to directly include Jupyter Notebooks, showing code cells and their results in both HTML and LaTeX output. Un-evaluated notebooks are automatically executed during the Sphinx build process. The library is actively maintained, with version 0.9.8 being the current release, and follows a regular release cadence.

Warnings

Install

Imports

Quickstart

To integrate Jupyter notebooks into Sphinx documentation, first install `nbsphinx` and `ipykernel`. Then, modify your `conf.py` to include `'nbsphinx'` in the `extensions` list. Finally, reference your `.ipynb` files (without the extension) within a `.. toctree::` directive in your `.rst` files. Notebooks should have a title (e.g., a Markdown heading in the first cell) to be correctly included.

# my_notebook.ipynb (Jupyter Notebook file)
# (Ensure this notebook has a title as its first cell, e.g., '# My Notebook Title')

import pandas as pd
df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
print(df)

# conf.py (Sphinx configuration file)
import os

project = 'My Project'
copyright = '2026, Your Name'
extensions = [
    'nbsphinx',
    'sphinx.ext.mathjax', # Often useful with notebooks
    'ipykernel' # Needed if notebooks are to be executed
]
html_theme = 'alabaster'

# index.rst (Sphinx master document)
..
  My Project
  ==========

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   my_notebook

# To build the documentation:
# 1. Create a Sphinx project: sphinx-quickstart (answer prompts)
# 2. Update conf.py and index.rst as shown above
# 3. Create my_notebook.ipynb
# 4. Run: sphinx-build -b html . _build

view raw JSON →