Examples¶
Basic REPL¶
.. py-repl::
Light theme, minimal¶
.. py-repl::
:theme: catppuccin-latte
:no-header:
:no-banner:
Startup script¶
The :src: option loads a Python script into the REPL namespace. If the script
defines a setup() function, its output is shown when the REPL starts.
.. py-repl::
:src: _static/setup.py
The startup script:
message = "Hello from the startup script!"
def setup():
print(message)
print("Try: message")
Replay session¶
Inline directive content is replayed with >>> prompts, syntax highlighting,
and live output. Doctest-style >>> / ... prefixes and bare ...
block terminators are stripped automatically.
.. py-repl::
:no-header:
:no-banner:
>>> x = 2 + 2
>>> print(f"{x=}")
>>> x * 10
>>> class Foo:
... x = 1
...
>>> Foo()
Combine a silent bootstrap file with a visible replay body:
.. py-repl::
:src: _static/setup.py
:no-header:
>>> print(message)
Use :replay: on :src: to replay a file with prompts instead of silent load:
.. py-repl::
:src: _static/replay_demo.py
:replay:
:no-header:
:no-banner:
The replay script:
greeting = "Hello from replay mode"
print(greeting)
greeting.upper()