pyexec

A sphinx extension for running python code and displaying both the input and output sphinx documentation.

In the ReStructuredText file, use the exec environment.:

.. exec::
    print 2 + 2

To output python code & the results in your documentation.

>> print 2 + 2
4

Note that you need to include the print statement for the output to be shown. To see it in action, checkout the Properties documentation.

Setup

PyExec is on pip:

pip install sphinxcontrib-pyexec

or install from source:

git clone https://github.com/3ptscience/sphinxcontrib-pyexec/

In the conf.py for your documentation, make sure you import pyexec:

import pyexec

and add pyexec to your extensions.

extensions = ['pyexec']

Developers

View the source code on github