pyreadline3: GNU Readline for Python on Windows

3.5.4 · active · verified Thu Apr 09

pyreadline3 is a Python implementation of GNU readline functionality, primarily designed for Windows environments where the native `readline` module is not available. It is a continuation of the `pyreadline` package, providing features like command history, tab completion, and keyboard shortcuts. Version 3.4+ of pyreadline3 supports Python 3.8+ and is actively maintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how pyreadline3 makes the `readline` module available and functional on Windows. After installation, `import readline` should seamlessly provide command-line editing features. The example shows a basic interactive loop with exit conditions.

import sys
# On Windows, pyreadline3 often patches sys.modules['readline']
# so standard 'import readline' works. Explicit import is also possible.
try:
    import readline
except ImportError:
    from pyreadline3 import Readline
    readline = Readline()

print("pyreadline3 is active. Try typing, using arrow keys for history, or Tab (if configured).")
print("Enter 'exit' to quit.")

while True:
    try:
        user_input = input(">>> ")
        if user_input.lower() == 'exit':
            break
        if user_input:
            print(f"You typed: {user_input}")
    except EOFError: # Ctrl+D
        print("\nExiting (Ctrl+D detected).")
        break
    except KeyboardInterrupt: # Ctrl+C
        print("\nExiting (Ctrl+C detected).")
        break

view raw JSON →