A Normal reStructuredText File

This is a normal RST file.

Note

Those still work!

Sphinx Directive for Including Notebooks

Notebooks can also be included directly in an RST file using the nbinclude directive. Below, we include An Included Notebook.

orphan:

An Included Notebook

This notebook is included with the nbinclude directive.

The cell below is stored unexecuted, but will be executed when included, just like notebooks included in a :toctree:. Notebooks with at least one executed cell will not be executed when included.

In [1]:
6 * 7
Out[1]:
42

The notebook was included with:

.. nbinclude:: subdir2/included.ipynb

Note

  • ../” is allowed here. In fact, you can include notebooks that are outside of the documentation directory!

Sphinx Directives for Jupyter Notebook Cells

For comparison, this is a “normal” Sphinx code block using ipython3 syntax highlighting:

%file helloworld.py
#!/usr/bin/env python3
print('Hello, world!')

The nbsphinx extension provides custom directives to show notebook cells:

In [42]:
6 * 7
Out[42]:
42

This was created with

.. nbinput:: ipython3
    :execution-count: 42

    6 * 7

.. nboutput::
    :execution-count: 42

    42