Pyrepl: A Pure Python Readline-a-like

0.11.4 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to embed a pyrepl-powered interactive console into a Python application using `InteractiveConsole` from `pyrepl.cmdrepl`. It creates a console instance, initializes it with the current global and local scope, and then starts an interactive loop. Users can execute Python code directly within this embedded REPL.

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()

view raw JSON →