Skip to content
Snippets Groups Projects
execute.md 8.43 KiB
jupytext:
  cell_metadata_filter: -all
  formats: md:myst
  text_representation:
    extension: .md
    format_name: myst
kernelspec:
  display_name: Python 3
  language: python
  name: python3

Execute and cache your pages

Jupyter Book can automatically run and cache any notebook pages. Notebooks can either be run each time the documentation is built, or cached locally so that notebooks will only be re-run when the code cells in a notebook have changed.

Caching behaviour is controlled with the execute: section in your _config.yml file. See the sections below for each configuration option and its effect.

:::{tip} If you'd like to execute code that is in your Markdown files, you can use the {code-cell} directive in MyST Markdown. See for more information. :::

Trigger notebook execution

By default, Jupyter Book will execute any content files that have a notebook structure and that are missing at least one output. This is equivalent to the following configuration in _config.yml`:

execute:
  execute_notebooks: auto

This will only execute notebooks that are missing at least one output. If the notebook has all of its outputs populated, then it will not be executed.

To force the execution of all notebooks, regardless of their outputs, change the above configuration value to:

execute_notebooks: force

To cache execution outputs with jupyter-cache, change the above configuration value to:

execute:
  execute_notebooks: cache

See {ref}execute/cache for more information.

To turn off notebook execution, change the above configuration value to:

execute:
  execute_notebooks: 'off'

(execute/exclude)=

Exclude files from execution

To exclude certain file patterns from execution, use the following configuration:

execute:
  exclude_patterns:
    - 'pattern1'
    - 'pattern2'
    - '*pattern3withwildcard'