Text of docs.python.org › 3.16 › library › readline.html as Styx crawled it on Oct 16, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

readline — GNU readline interface — Python 3.16.0a1 documentation

Navigation index modules | next | previous | Python » 3.16.0a1 Documentation » The Python standard library » Text Processing Services » readline — GNU readline interface | Theme | readline — GNU readline interface ¶ The readline module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. This module can be used directly, or via the rlcompleter module, which supports completion of Python identifiers at the interactive prompt.

Settings made using this module affect the behaviour of both the interpreter’s interactive prompt and the prompts offered by the built-in input() function. Readline keybindings may be configured via an initialization file, typically .inputrc in your home directory. See Readline Init File in the GNU Readline manual for information about the format and allowable constructs of that file, and the capabilities of the Readline library in general.

Availability : not Android, not iOS, not WASI. This module is not supported on mobile platforms or WebAssembly platforms . This is an optional module . If it is missing from your copy of CPython, look for documentation from your distributor (that is, whoever provided Python to you). If you are the distributor, see Requirements for optional modules . Availability : Unix. Note The underlying Readline library API may be implemented by the editline ( libedit ) library instead of GNU readline.

On macOS the readline module detects which library is being used at run time. The configuration file for editline is different from that of GNU readline. If you programmatically load configuration strings you can use backend to determine which library is being used. If you use editline / libedit readline emulation on macOS, the initialization file located in your home directory is named .editrc . For example, the following content in ~/.editrc will turn ON vi keybindings and TAB completion: python : bind - v python : bind ^ I rl_complete Also note that different libraries may use different history file formats.

When switching the underlying library, existing history files may become unusable. readline. backend ¶ The name of the underlying Readline library being used, either "readline" or "editline" . Added in version 3.13. readline. READLINE_VERSION_INFO ¶ A named tuple containing the two components of the Readline library version that was used for building the module: major and minor . Both values are integers. The components can also be accessed by name, so readline.READLINE_VERSION_INFO[0] is equivalent to readline.READLINE_VERSION_INFO.major and so on.

This may be different from the Readline library actually used at runtime, which is available as readline_version_info . With the editline backend, this is the version of the Readline interface emulated by libedit, not the version of libedit. Added in version 3.16. readline. readline_version_info ¶ A named tuple containing the version of the Readline library actually loaded by the interpreter, with the same fields as READLINE_VERSION_INFO .

Added in version 3.16. readline. readline_version ¶ The version string of the Readline library actually loaded by the interpreter, like '8.3' . With the editline backend, this is 'EditLine wrapper' . Added in version 3.16. Init file ¶ The following functions relate to the init file and user configuration: readline. parse_and_bind ( string ) ¶ Execute the init line provided in the string argument. This calls rl_parse_and_bind() in the underlying library. readline. read_init_file ( [ filename ] ) ¶ Execute a readline initialization file.

The default filename is the last filename used. This calls rl_read_init_file() in the underlying library. It raises an auditing event open with the file name if given, and "<readline_init_file>" otherwise, regardless of which file the library resolves. Changed in version 3.14: The auditing event was added. Line buffer ¶ The following functions operate on the line buffer: readline. get_line_buffer ( ) ¶ Return the current contents of the line buffer ( rl_line_buffer in the underlying library). readline. insert_text ( string ) ¶ Insert text into the line buffer at the cursor position.

This calls rl_insert_text() in the underlying library, but ignores the return value. readline. redisplay ( ) ¶ Change what’s displayed on the screen to reflect the current contents of the line buffer. This calls rl_redisplay() in the underlying library. History file ¶ The following functions operate on a history file: readline. read_history_file ( [ filename ] ) ¶ Load a readline history file, and append it to the history list.

The default filename is ~/.history . This calls read_history() in the underlying library and raises an auditing event open with the file name if given and "~/.history" otherwise. Changed in version 3.14: The auditing event was added. readline. write_history_file ( [ filename ] ) ¶ Save the history list to a readline history file, overwriting any existing file. The default filename is ~/.history . This calls write_history() in the underlying library and raises an auditing event open with the file name if given and "~/.history" otherwise.

Changed in version 3.14: The auditing event was added. readline. append_history_file ( nelements [ , filename ] ) ¶ Append the last nelements items of history to a file. The default filename is ~/.history . The file must already exist. This calls append_history() in the underlying library. This function only exists if Python was compiled for a version of the library that supports it. It raises an auditing event open with the file name if given and "~/.history" otherwise.

Added in version 3.5. Changed in version 3.14: The auditing event was added. readline. get_history_length ( ) ¶ readline. set_history_length ( length ) ¶ Set or return the desired number of lines to save in the history file. The write_history_file() function uses this value to truncate the history file, by calling history_truncate_file() in the underlying library. Negative values imply unlimited history file size. History list ¶ The following functions operate on a global history list: readline. clear_history ( ) ¶ Clear the current history.

This calls clear_history() in the underlying library. The Python function only exists if Python was compiled for a version of the library that supports it. readline. get_current_history_length ( ) ¶ Return the number of items currently in the history. (This is different from get_history_length() , which returns the maximum number of lines that will be written to a history file.) readline. get_history_item ( index ) ¶ Return the current contents of history item at index .

The item index is one-based. This calls history_get() in the underlying library. readline. remove_history_item ( pos ) ¶ Remove history item specified by its position from the history. The position is zero-based. This calls remove_history() in the underlying library. readline. replace_history_item ( pos , line ) ¶ Replace history item specified by its position with line . The position is zero-based. This calls replace_history_entry() in the underlying library. readline. add_history ( line ) ¶ Append line to the history buffer, as if it was the last line typed.

This calls add_history() in the underlying library. readline. set_auto_history ( enabled ) ¶ Enable or disable automatic calls to add_history() when reading input via readline. The enabled argument should be a Boolean value that when true, enables auto history, and that when false, disables auto history. Added in version 3.6. CPython implementation detail: Auto history is enabled by default, and changes to this do not persist across multiple sessions.

Startup hooks ¶ readline. set_startup_hook ( [ function ] ) ¶ Set or remove the function invoked by the rl_startup_hook callback of the underlying library. If function is specified, it will be used as the new hook function; if omitted or None , any function already installed

The rest of this page is on the live site.