Sphinx extension to add pyodide directive
Project description
sphinx-pyodide
Sphinx extension to add a pyodide directive for embedding executable Python code blocks in documentation using Pyodide (Python in the browser via WebAssembly).
For full details and examples, refer to the documentation.
How to Use
Install with pip, uv, or similar:
pip install sphinx-pyodide
Enable the extension by including in your Sphinx conf.py:
extensions = ["sphinx_pyodide"]
The output blocks support light and dark mode. For best results, use a Sphinx theme with built-in dark mode support such as Furo or the PyData Sphinx Theme.
Use in documentation files. Build-time output is displayed as static output below each block. Interactive execution requires opt-in — click the Enable Interactive button in the note above the first block to load Pyodide and run blocks live in the browser.
.. pyodide::
print("Hello from Pyodide!")
import numpy as np
print(np.array([1, 2, 3]))
Options
| Option | Type | Description |
|---|---|---|
:packages: |
string | Comma-separated PyPI packages to load (e.g., numpy, pandas). Local .whl files are also supported. |
:editable: |
flag | Allow users to edit the code before running. |
:output: |
string | Static output displayed in the output panel until interactive execution is enabled. |
:show-errors: |
flag | Display runtime errors in the live browser output. |
:setup-code: |
string | Python code to run once before the main block (e.g., imports). |
Development
Setup
Install development dependencies; install pre-commit hooks on first setup.
uv sync --dev
pre-commit install
Testing
Tests use sphinx.testing fixtures via pytest.
pytest tests/
pytest tests/ -k test_name
pytest tests/ --cov=src/sphinx_pyodide
Build Documentation
# One-time build
sphinx-build -b html docs/source docs/build
# Auto-reload with live preview (recommended for development)
sphinx-autobuild docs/source docs/build
Note: Pyodide blocks that install dependencies from local wheels
require an HTTP server (file:// will not work due to CORS).
Options are to build and serve with python -m http.server -d docs/build
or serve with sphinx-autobuild.
Acknowledgments
Substantial portions of this code were developed with assistance from agentic AI coding tools (primarily ClaudeCode & OpenCode and associated models).
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinx_pyodide-0.1.1.tar.gz.
File metadata
- Download URL: sphinx_pyodide-0.1.1.tar.gz
- Upload date:
- Size: 108.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8568e78cda73b4e7469712084f61e39eedf3cd6b210b0fda16319a246156a59
|
|
| MD5 |
107e1e5e7a86bd82d3bea13a5f7b6e9c
|
|
| BLAKE2b-256 |
c6f068a9e03a3c30719f0a725bad9a1b54dfbf2a70b9661111564fc9a5823357
|
File details
Details for the file sphinx_pyodide-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sphinx_pyodide-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f92f52438cc6d600e9a378a3c0e3048a8751b506506a02118d05e203f5b91ebb
|
|
| MD5 |
71519f1cabbf8039e3a96ab3ccf0aa36
|
|
| BLAKE2b-256 |
3c466f6d4da49d719b72050b7f600b0403b1f697cf8b3402e6c7da51469ba2f5
|