A Jupyter Notebook Sphinx reader built on top of the MyST markdown parser.
npx @tessl/cli install tessl/pypi-myst-nb@1.3.0A comprehensive Sphinx extension and docutils parser for Jupyter notebooks containing MyST Markdown. MyST-NB bridges the gap between interactive notebook development and static documentation systems, enabling seamless integration of executable notebooks into documentation workflows with full support for code execution, output rendering, and cross-referencing.
pip install myst-nbimport myst_nbFor Sphinx configuration:
# In conf.py
extensions = ['myst_nb']For gluing variables:
from myst_nb import glueFor CLI usage:
from myst_nb.cli import quickstart, md_to_nb# In your Sphinx conf.py
extensions = ['myst_nb']
# Optional configuration
nb_execution_mode = "auto"
nb_execution_timeout = 30from myst_nb import glue
import matplotlib.pyplot as plt
# Create a plot
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4], [1, 4, 2, 3])
# Glue the figure for later reference
glue("my_plot", fig, display=False)Then reference in markdown:
{glue:figure} `my_plot`
:name: "fig-example"
This is my plot# Create a new MyST-NB project
mystnb-quickstart
# Convert MyST markdown to Jupyter notebook
mystnb-to-jupyter input.md output.ipynb
# Generate HTML from notebook
mystnb-docutils-html notebook.ipynb output.htmlMyST-NB follows a modular architecture with clear separation of concerns:
This design enables flexible notebook processing pipelines while maintaining compatibility with both Sphinx documentation systems and standalone docutils processing.
Core Sphinx integration functionality including setup, configuration, parsing, rendering, and post-processing transforms for notebook content.
def setup(app)Comprehensive configuration system with 40+ options controlling execution, rendering, output formatting, and display behavior.
class NbParserConfig:
execution_mode: str
execution_timeout: int
render_plugin: str
remove_code_source: bool
# ... 40+ configuration fieldsReading, parsing, and processing of Jupyter notebooks in various formats including standard .ipynb and MyST markdown notebooks.
def standard_nb_read(text: str) -> nbf.NotebookNode
def create_nb_reader(...) -> NbReader | None
def read_myst_markdown_notebook(...)Multiple execution strategies for notebook cells including direct execution, cached execution via jupyter-cache, and inline variable evaluation.
class NotebookClientBase
class ExecutionResult
def create_client(...) -> NotebookClientBaseFlexible rendering system supporting multiple output formats with extensible MIME type handling and customizable renderers.
class NbElementRenderer
class MimeData
def load_renderer(name: str) -> type[NbElementRenderer]Variable gluing system for cross-referencing computed results across notebook cells and documentation, with roles and directives for content insertion.
def glue(name: str, variable, display: bool = True) -> NoneRole for downloading executed notebooks, allowing users to access processed notebook files from the documentation.
class NbDownloadRoleComplete command-line interface for project creation, notebook conversion, and document generation across multiple output formats.
def quickstart(args: list[str] | None = None)
def md_to_nb(args: list[str] | None = None)Standalone docutils parser and renderer for direct notebook processing without Sphinx, enabling integration into custom documentation pipelines.
class Parser(MystParser)
class DocutilsNbRenderer(DocutilsRenderer, MditRenderMixin)