Pyrepl: A Pure Python Readline-a-like
pyrepl is a readline-a-like library implemented entirely in pure Python, providing advanced command-line interface features. It offers sane multi-line editing, history management with incremental search, and robust completion capabilities. Designed for integration, it avoids global variables, allowing multiple independent readers within an application's event loop. It requires Python 3.8 or newer, with the current version being 0.11.4.
Warnings
- gotcha Pyrepl's default keybindings for history navigation differ from standard terminal behavior. Instead of up/down arrow keys, use `Ctrl+P` (previous) and `Ctrl+N` (next) to cycle through command history. Arrow keys are used for moving within the current line.
- gotcha There is significant confusion between the `pyrepl` library (this package) and `PyREPL`, the new interactive interpreter *based on* `pyrepl` that is becoming the default for CPython 3.13. While related, they are distinct. CPython's `PyREPL` has its own development and rollout nuances (e.g., specific platform support like Windows), which may not directly apply to the standalone `pyrepl` library.
Install
-
pip install pyrepl
Imports
- InteractiveConsole
from pyrepl.cmdrepl import InteractiveConsole
Quickstart
import sys
from pyrepl.cmdrepl import InteractiveConsole
def main():
# Instantiate an interactive console
console = InteractiveConsole(locals=globals())
# Start the interactive loop
print("\nWelcome to pyrepl interactive console! Type 'exit()' or Ctrl-D to quit.")
console.interact()
print("Exiting pyrepl console.")
if __name__ == '__main__':
main()