explaingit

prompt-toolkit/python-prompt-toolkit

10,447PythonAudience · developerComplexity · 2/5Setup · easy

TLDR

A Python library for building interactive terminal programs with autocomplete, syntax highlighting, history search, and mouse support, like building a mini shell in Python.

Mindmap

mindmap
  root((repo))
    What it does
      Interactive terminal input
      readline replacement
      Rich typing experience
    Features
      Syntax highlighting
      Autocomplete
      Multi-line editing
      Mouse support
    Platforms
      Linux and macOS
      Windows
      FreeBSD
    Audience
      Python developers
      CLI tool builders
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add autocomplete and syntax highlighting to a custom Python CLI tool or REPL as the user types.

USE CASE 2

Build an interactive terminal shell in Python with command history, Vi or Emacs key bindings, and search.

USE CASE 3

Create a multi-line text editor inside a terminal application with mouse support and Unicode handling.

Tech stack

PythonPygments

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

python-prompt-toolkit is a Python library for building interactive command-line programs, meaning programs that run in a terminal and let users type input in a rich, responsive way. If you have ever used a terminal shell that shows syntax coloring as you type, offers autocomplete suggestions, or lets you scroll through history, those features are the kind of thing this library makes possible in your own Python program. The library is described as a potential replacement for GNU readline, which is the longstanding Unix tool that adds line-editing capabilities (like pressing the up arrow to recall the previous command) to terminal programs. prompt_toolkit can do everything readline does, and more. Features listed in the README include: syntax highlighting as the user types, multi-line input editing, code completion, both Emacs and Vi keyboard shortcuts, search through input history, mouse support, auto-suggestions similar to the fish shell, and support for Unicode characters including double-width Chinese text. Installation is a single pip command. The library works on Linux, macOS, FreeBSD, OpenBSD, and Windows. The README notes that Windows support is best on recent Windows 10 where the terminal understands standard escape codes, with a fallback for older Windows versions. The simplest usage is just a few lines: import the prompt function, call it with a message string, and it returns whatever the user typed. More complex uses involve customizing the completion logic, adding syntax highlighting, or building a full interactive shell. The repository ships an examples directory with small programs that each demonstrate one feature. ptpython, an interactive Python shell, is listed as a real-world application built on top of this library. The library has only two external dependencies (Pygments for syntax highlighting and wcwidth for character width calculations), keeping it lightweight relative to what it provides.

Copy-paste prompts

Prompt 1
Using python-prompt-toolkit, help me build a Python CLI tool that autocompletes commands from a list I define and highlights keywords as the user types.
Prompt 2
Show me how to use python-prompt-toolkit to create a multi-line input editor in my Python app that supports Ctrl+R history search and Vi key bindings.
Prompt 3
I want to add a custom prompt to my Python script using prompt_toolkit that accepts both single and multi-line input with syntax coloring. Walk me through it.
Prompt 4
Help me build an interactive Python shell similar to ptpython using python-prompt-toolkit with tab completion and persistent input history.
Open on GitHub → Explain another repo

← prompt-toolkit on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.