Sphinx Thebe

0.3.1 · active · verified Thu Apr 16

Sphinx Thebe is a Sphinx extension that integrates interactive code blocks into documentation using Thebe.js and Binder. It allows readers to execute code examples directly in their browser against a live Jupyter kernel. The current version is 0.3.1, with releases occurring periodically to address Sphinx compatibility and feature enhancements.

Common errors

Warnings

Install

Imports

Quickstart

To quickly get started, install the package, then add `sphinx_thebe` to your `conf.py` extensions list. Crucially, define a `thebe_config` dictionary specifying your BinderHub URL and kernel details. Finally, use the `thebe-button` directive followed by a code block in your reStructuredText or MyST Markdown files.

# 1. Install sphinx-thebe:
# pip install sphinx-thebe

# 2. In your Sphinx project's conf.py, add 'sphinx_thebe' to extensions:
# extensions = [
#     'sphinx_thebe'
# ]

# 3. Configure thebe_config (replace with your BinderHub URL and kernel):
# thebe_config = {
#     'repository_url': 'https://github.com/binder-examples/jupyter-stacks-datascience',
#     'repository_branch': 'master',
#     'binderhub_url': 'https://mybinder.org',
#     'kernel_name': 'python3',
#     'code_selector': 'div.highlight',
#     'always_load': false
# }

# 4. In a reStructuredText file (.rst) or MyST Markdown file (.md) write:
# .. thebe-button::
#    :label: Run this code!

# .. code-block:: python

#    print('Hello, Thebe!')
#    x = 1 + 1
#    print(f'x is {x}')

# 5. Build your Sphinx documentation:
# make html

view raw JSON →