or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/pypi-readline

GNU readline support for Python on platforms without readline

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

To install, run

npx @tessl/cli install tessl/pypi-readline@2.6.0

0

# readline

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: readline

7

- **Package Type**: pypi

8

- **Language**: Python (C Extension)

9

- **Installation**: `pip install readline`

10

- **Version**: 2.6.4

11

12

## Core Imports

13

14

```python

15

import readline

16

```

17

18

## Basic Usage

19

20

```python

21

import readline

22

23

# Configure readline

24

readline.parse_and_bind('tab: complete') # Enable tab completion

25

readline.parse_and_bind('set editing-mode vi') # Set vi editing mode

26

27

# Set up history

28

readline.read_history_file() # Load history from ~/.history

29

readline.set_history_length(1000) # Limit history to 1000 entries

30

31

# Set up completion

32

def completer(text, state):

33

options = ['hello', 'help', 'history', 'home']

34

matches = [opt for opt in options if opt.startswith(text)]

35

return matches[state] if state < len(matches) else None

36

37

readline.set_completer(completer)

38

readline.set_completer_delims(' \t\n')

39

40

# Interactive input with readline features

41

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

42

43

# Save history when done

44

readline.write_history_file()

45

```

46

47

## Architecture

48

49

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

50

51

- **Configuration**: Parse readline init files and configure behavior

52

- **History Management**: Persistent command history with file I/O and manipulation

53

- **Line Editing**: Buffer access and text insertion for command-line editing

54

- **Tab Completion**: Customizable completion system with hooks and delimiters

55

- **Event Hooks**: Startup, pre-input, and display hooks for advanced customization

56

57

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

58

59

## Capabilities

60

61

### Configuration and Initialization

62

63

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

64

65

```python { .api }

66

def parse_and_bind(string): ...

67

def read_init_file(filename=None): ...

68

```

69

70

[Configuration](./configuration.md)

71

72

### History Management

73

74

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

75

76

```python { .api }

77

def read_history_file(filename=None): ...

78

def write_history_file(filename=None): ...

79

def set_history_length(length): ...

80

def get_history_length(): ...

81

def add_history(string): ...

82

```

83

84

[History Management](./history.md)

85

86

### Line Editing

87

88

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

89

90

```python { .api }

91

def get_line_buffer(): ...

92

def insert_text(string): ...

93

def redisplay(): ...

94

```

95

96

[Line Editing](./line-editing.md)

97

98

### Tab Completion

99

100

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

101

102

```python { .api }

103

def set_completer(function=None): ...

104

def get_completer(): ...

105

def set_completer_delims(string): ...

106

def get_completer_delims(): ...

107

```

108

109

[Tab Completion](./completion.md)

110

111

### Event Hooks

112

113

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

114

115

```python { .api }

116

def set_startup_hook(function=None): ...

117

def set_pre_input_hook(function=None): ...

118

def set_completion_display_matches_hook(function=None): ...

119

```

120

121

[Event Hooks](./hooks.md)