Skip to main content

Sphinx extension: NoteBook Execution Patterns

Introduction

A Sphinx extension to execute Jupyter NoteBooks (*.ipynb) and Text-based NoteBooks (*.md) based on include and exclude patterns instead of only exclude patterns.

This extension also applies the mystnb patch from JupyterBook-Patches.

Installation

To install the Sphinx-NB-Execution-Patterns extension, follow these steps:

Step 1: Install the Package

Install the Sphinx-NB-Execution-Patterns package using pip:

pip install sphinx-nb-execution-patterns

Step 2: Add to requirements.txt

Make sure that the package is included in your project's requirements.txt to track the dependency:

sphinx-nb-execution-patterns

Step 3: Enable in _config.yml

In your _config.yml file, add the extension to the list of Sphinx extra extensions:

sphinx: 
    extra_extensions:
        - sphinx_nb_execution_patterns

Configuration

You can configure the extension in your _config.yml file. Here are the available options:

  • nb_execution_includepatterns: A list of glob patterns to indicate notebooks that must be included for execution. Default is an empty list.
  • nb_execution_patterns_method: Sets the method used when both include and exclude patterns are provided. Allowed values are:
    • only_include (default): Notebooks matching the include patterns are executed. All exclude patterns are ignored.
    • only_exclude: Notebooks matching the exclude patterns are excluded from execution, all other notebooks are executed. All include patterns are ignored. This method is equivalent to the default behavior of JupyterBook/Sphinx.
    • exclude_include: Notebooks matching the exclude patterns are excluded from execution, unless they also match the include patterns. All other notebooks are executed.
    • include_exclude: Notebooks matching the include patterns are executed, unless they also match the exclude patterns.

This extension will only have an effect if include patterns are provided.

Example Configuration

Here is an example configuration in _config.yml using both include and exclude patterns and JupyterBook syntax:

execute:
  execute_notebooks: auto
  exclude_patterns:
  - "*NB1*"

sphinx:
  config:
    nb_execution_includepatterns:
      - "*sol.ipynb"
    nb_execution_patterns_method: "include_exclude"

Here is the same example configuration in _config.yml using Sphinx syntax:

sphinx:
  config:
    nb_execution_mode: "auto"
    nb_execution_excludepatterns:
      - "*NB1*"
    nb_execution_includepatterns:
      - "*sol.ipynb"
    nb_execution_patterns_method: "include_exclude"

For the given example, all notebooks matching *sol.ipynb will be executed, unless they also match *NB1*.

If nb_execution_patterns_method is set to only_include, all notebooks matching *sol.ipynb will be executed, and the exclude pattern will be ignored.

If nb_execution_patterns_method is set to only_exclude, all notebooks matching *sol.ipynb will be excluded from execution, all other notebooks are executed, and the include pattern will be ignored.

If nb_execution_patterns_method is set to exclude_include, all notebooks matching *NB1* will be excluded from execution, unless they also match *sol.ipynb. All other notebooks will be executed.

Contribute

This tool's repository is stored on GitHub. If you'd like to contribute, you can create a fork and open a pull request on the GitHub repository.

The README.md of the branch Manual is also part of the TeachBooks manual.

Metadata

Release files for sphinx-nb-execution-patterns 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinx-nb-execution-patterns 1.1.0
File Size Uploaded Provenance
sphinx_nb_execution_patterns-1.1.0.tar.gz 9.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-nb-execution-patterns 1.1.0
File Interpreter ABI Platform
sphinx_nb_execution_patterns-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.7 kB

Release files / sphinx_nb_execution_patterns-1.1.0.tar.gz

Download URL sphinx_nb_execution_patterns-1.1.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d8b99c6393ebfbafe4def3030c0054d1140e6dcf884f09cdd9228c4ffe3bde48
BLAKE2b-256 checksum
How to use checksums
838908bf2f5609ae728e39456cbacfc5060d4e2a8204a273c8517495973b5c75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 8, 2026.

Transparency log

Release files / sphinx_nb_execution_patterns-1.1.0-py3-none-any.whl

Download URL sphinx_nb_execution_patterns-1.1.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2cc93535c5ffeccb70126fc5f3234bda8b9c78f99bd9cf416ea9d4ea7dd62db8
BLAKE2b-256 checksum
How to use checksums
ef24a4bbc812400aae41072d7b42f99c8787a097618a1084e7439aa03de3c73d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 8, 2026.

Transparency log

Security for sphinx-nb-execution-patterns 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sphinx_nb_execution_patterns-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 8, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page