PyReadline

2.1 · maintenance · verified Thu Apr 16

PyReadline (version 2.1) is a Python implementation of GNU readline functionality, primarily designed for Windows, to provide enhanced command-line editing features like history and tab completion. The project's last release was in 2015, and it is largely unmaintained. For users on Python 3.8 and newer, the community-maintained fork `pyreadline3` is the recommended alternative for compatible functionality.

Common errors

Warnings

Install

Imports

Quickstart

PyReadline primarily enhances the standard Python interactive prompt and the `input()` function on Windows. After installation, its features are generally active without explicit imports, though `import readline` will expose its API. This example demonstrates basic input and checks a `readline` function, noting potential compatibility issues with older versions.

import sys

# pyreadline enhances the built-in input() function on Windows
# if it's installed and correctly configured.
# The primary use is passive: install it, and your Python REPL
# and input() calls will have readline features.

print('Type something (with history and tab completion if pyreadline is active):')
try:
    user_input = input('>>> ')
    print(f'You typed: {user_input}')

    # Example of a readline function (available via the shim)
    # Requires pyreadline to be active and have bound these functions
    import readline
    # The following line might raise AttributeError if pyreadline isn't fully set up or patched
    print(f'Current history length: {readline.get_current_history_length()}')
except EOFError:
    print('\nExiting.')
except AttributeError as e:
    print(f'Readline attribute error: {e}. PyReadline might not be fully loaded or compatible with your Python version.')
except Exception as e:
    print(f'An unexpected error occurred: {e}')

view raw JSON →