CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-readline

GNU readline support for Python on platforms without readline

Pending
Overview
Eval results
Files

readline

GNU readline support for Python on platforms without readline. This module provides Python bindings to the GNU readline library, enabling command-line editing, history management, and tab completion functionality for interactive Python sessions.

Package Information

  • Package Name: readline
  • Package Type: pypi
  • Language: Python (C Extension)
  • Installation: pip install readline
  • Version: 2.6.4

Core Imports

import readline

Basic Usage

import readline

# Configure readline
readline.parse_and_bind('tab: complete')  # Enable tab completion
readline.parse_and_bind('set editing-mode vi')  # Set vi editing mode

# Set up history
readline.read_history_file()  # Load history from ~/.history
readline.set_history_length(1000)  # Limit history to 1000 entries

# Set up completion
def completer(text, state):
    options = ['hello', 'help', 'history', 'home']
    matches = [opt for opt in options if opt.startswith(text)]
    return matches[state] if state < len(matches) else None

readline.set_completer(completer)
readline.set_completer_delims(' \t\n')

# Interactive input with readline features
user_input = input("Enter command: ")  # Now has history, completion, editing

# Save history when done
readline.write_history_file()

Architecture

The readline module provides a Python interface to GNU readline's command-line editing capabilities:

  • Configuration: Parse readline init files and configure behavior
  • History Management: Persistent command history with file I/O and manipulation
  • Line Editing: Buffer access and text insertion for command-line editing
  • Tab Completion: Customizable completion system with hooks and delimiters
  • Event Hooks: Startup, pre-input, and display hooks for advanced customization

This module automatically integrates with Python's input() function, providing enhanced command-line editing for interactive sessions.

Capabilities

Configuration and Initialization

Core configuration functions for setting up readline behavior, parsing initialization files, and configuring the readline environment.

def parse_and_bind(string): ...
def read_init_file(filename=None): ...

Configuration

History Management

Comprehensive history management including file operations, length control, and direct history manipulation with functions for reading, writing, and modifying command history.

def read_history_file(filename=None): ...
def write_history_file(filename=None): ...
def set_history_length(length): ...
def get_history_length(): ...
def add_history(string): ...

History Management

Line Editing

Functions for accessing and manipulating the current line buffer, enabling custom editing behavior and text insertion capabilities.

def get_line_buffer(): ...
def insert_text(string): ...
def redisplay(): ...

Line Editing

Tab Completion

Comprehensive tab completion system with customizable completion functions, delimiter configuration, and completion context access.

def set_completer(function=None): ...
def get_completer(): ...
def set_completer_delims(string): ...
def get_completer_delims(): ...

Tab Completion

Event Hooks

Advanced customization through event hooks that execute at specific points in the readline process, enabling custom display and input handling.

def set_startup_hook(function=None): ...
def set_pre_input_hook(function=None): ...
def set_completion_display_matches_hook(function=None): ...

Event Hooks

Install with Tessl CLI

npx tessl i tessl/pypi-readline
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/readline@2.6.x