Sphinx directive that adds an interactive Run button to code files via a self-hosted codeapi instance
Project description
sphinxcontrib-coderun
A Sphinx extension that adds an interactive Run button to code files in your documentation. Powered by a self-hosted codeapi instance — you bring your own server, this extension wires it into Sphinx.
How it works
- You self-host a codeapi server (supports C, Python, Go, Rust, and many more).
- You add
.. coderun::directives to your.rstfiles. - When a reader clicks Run, the code is sent to your codeapi server, executed in an isolated sandbox, and the output appears inline on the page.
Nothing is shared with third-party services — all execution happens on your own infrastructure.
Install
pip install sphinxcontrib-coderun
Configuration
In your conf.py:
extensions = [..., "sphinxcontrib.coderun"]
# URL of your self-hosted codeapi instance
coderun_url = "https://codapi.example.com"
# Default sandbox (matches a sandbox configured on your codeapi server)
coderun_sandbox = "gcc"
Both settings can be overridden per-directive (see below).
Usage
Replace .. literalinclude:: with .. coderun:: wherever you want a Run button:
.. coderun:: cprogs/hello.c
:language: c
Override the sandbox or URL for a specific snippet:
.. coderun:: examples/hello.py
:language: python
:sandbox: python
:url: https://codapi.example.com
All standard literalinclude options work — :lines:, :linenos:,
:emphasize-lines:, etc.
Self-hosting codeapi
You need a running codeapi instance that the browser can reach. Quickstart:
# Pull the server and a sandbox image
docker pull nalgeon/codapi
docker pull codapi/gcc # or python, go, etc.
# Run the server
docker run -p 1313:1313 -v /path/to/config:/opt/codapi nalgeon/codapi
For production deployment (Kubernetes, TLS, rate limiting) see the codeapi documentation.
Point coderun_url at the public URL of your server and you're done.
Development
Project structure
sphinxcontrib-coderun/
├── pyproject.toml
├── LICENSE
├── README.md
└── sphinxcontrib/
├── __init__.py # namespace package
└── coderun/
├── __init__.py # directive + Sphinx setup()
└── static/
└── coderun.css # Run button styling
Local setup
git clone https://github.com/uthcode/sphinxcontrib-coderun
cd sphinxcontrib-coderun
pip install -e .
To test against a Sphinx project, add to its conf.py:
extensions = [..., "sphinxcontrib.coderun"]
coderun_url = "http://localhost:1313" # local codeapi for dev
coderun_sandbox = "gcc"
Building a distribution
pip install build twine
python -m build
# produces dist/sphinxcontrib_coderun-X.Y.Z.tar.gz
# dist/sphinxcontrib_coderun-X.Y.Z-py3-none-any.whl
Validate before uploading:
python -m twine check dist/*
Publishing to PyPI
Create an API token at pypi.org/manage/account/token scoped to this project, then:
python -m twine upload dist/*
# Username: __token__
# Password: pypi-AgEI...
Releasing a new version
- Bump
versioninpyproject.toml. - Delete
dist/. - Run
python -m build. - Run
python -m twine upload dist/*.
License
MIT
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 sphinxcontrib_coderun-0.1.0.tar.gz.
File metadata
- Download URL: sphinxcontrib_coderun-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9822528087cf4bdd59d6321d686a0373c9992742250e2582aae7eb13b021f31
|
|
| MD5 |
1b29ed9e12ff480e40375f6752a4b716
|
|
| BLAKE2b-256 |
7e69288953d8d810c52e3af86b36c8031cde16ffe6b5f8ccfab530df23453036
|
Provenance
The following attestation bundles were made for sphinxcontrib_coderun-0.1.0.tar.gz:
Publisher:
publish.yml on uthcode/sphinxcontrib-coderun
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinxcontrib_coderun-0.1.0.tar.gz -
Subject digest:
e9822528087cf4bdd59d6321d686a0373c9992742250e2582aae7eb13b021f31 - Sigstore transparency entry: 1628046139
- Sigstore integration time:
-
Permalink:
uthcode/sphinxcontrib-coderun@f51e50679039de038e2b09ddc1f3f1aa8f4d3893 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/uthcode
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f51e50679039de038e2b09ddc1f3f1aa8f4d3893 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sphinxcontrib_coderun-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sphinxcontrib_coderun-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c6dcc4db5a28d01f48881e1d38ce7db6f2f4221b80409a3b0ccb73464337120
|
|
| MD5 |
f6dc731b82aa679dbab1fa92f1a87a8d
|
|
| BLAKE2b-256 |
a2c910aea27f92585654b37edbccdc45344613a7de22c55ebe678041b615b1b5
|
Provenance
The following attestation bundles were made for sphinxcontrib_coderun-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on uthcode/sphinxcontrib-coderun
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinxcontrib_coderun-0.1.0-py3-none-any.whl -
Subject digest:
9c6dcc4db5a28d01f48881e1d38ce7db6f2f4221b80409a3b0ccb73464337120 - Sigstore transparency entry: 1628046142
- Sigstore integration time:
-
Permalink:
uthcode/sphinxcontrib-coderun@f51e50679039de038e2b09ddc1f3f1aa8f4d3893 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/uthcode
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f51e50679039de038e2b09ddc1f3f1aa8f4d3893 -
Trigger Event:
push
-
Statement type: