Skip to main content

A Sphinx extension for embedding pyrepl-web Python REPLs in documentation.

Project description

sphinx-pyrepl-web

Sphinx extension to embed pyrepl-web in documentation.

Install

pip install sphinx-pyrepl-web

For development:

pip install -e ".[test,docs]"

Usage

Add the extension to the target project's conf.py:

extensions = [
    "sphinx_pyrepl_web",
]

Embed a REPL with the py-repl directive:

.. py-repl::

.. py-repl::
   :theme: catppuccin-latte
   :no-header:

.. py-repl::
   :src: setup.py
   :packages: numpy

.. py-repl::
   :no-header:

   >>> import math
   >>> math.sqrt(16)

Directive options

Most options drive pyrepl-web's attributes, with a few exceptions unique to this extension:

Option Description pyrepl-web attr?
:theme: Color theme (catppuccin-mocha, catppuccin-latte)
:packages: Comma-separated PyPI packages to preload
:repl-title: Title in the REPL header
:src: Path to a Python startup script
:replay: Replay :src: with interactive prompts instead of silent load
:silent: Keep :src: silent even when combined with a directive body
:strip-prompts: Strip >>> / ... prefixes from directive body
:no-header: Hide the header bar
:no-buttons: Hide copy/clear buttons
:readonly: Disable input
:no-banner: Hide the Python version banner

Directive body content (inline Python in the .. py-repl:: block) is also extension-only: it is written to _static/pyrepl/ at build time and emitted as replay-src.

Optional Sphinx config:

pyrepl_js = "../pyrepl.js"  # default; path to the pyrepl-web loader script

Updating pyrepl-web

Since chrizzFTD/pyrepl-web is a fork, this sphinx extension vendors the JavaScript assets for easier distribution. To update them, run:

python scripts/vendor_repl.py

The grill branch is used by default. Use the branch argument to specify a different one:

python scripts/vendor_repl.py --branch cursor/repl-startup-replay-2e3f

This requires git and Bun.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_pyrepl_web-0.1.0.tar.gz (283.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_pyrepl_web-0.1.0-py3-none-any.whl (282.2 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_pyrepl_web-0.1.0.tar.gz.

File metadata

  • Download URL: sphinx_pyrepl_web-0.1.0.tar.gz
  • Upload date:
  • Size: 283.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for sphinx_pyrepl_web-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f78401b20780fe7872ab6fa059b7963db6f8bfdb8d472d640dcbb68f4c7f5e76
MD5 73d4276b34c54bee4e77f21d92f0e26c
BLAKE2b-256 08938961a5f2494168613b7bfb22f401f7a9e14b7cd2095624f4f73d12b5ac3a

See more details on using hashes here.

File details

Details for the file sphinx_pyrepl_web-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_pyrepl_web-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63a264d167a31e0891f20e60d9f73b48f5b94f043e06629a25e024904745bb45
MD5 40ff84d71ce66eeb6d7a15fffe815d6a
BLAKE2b-256 17bd777e8013793027a58848179cbc5a9ce116158190989c63c5dba6407a9caa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page