prompt_toolkit

A pure-Python library for building powerful interactive command-line applications

Library
PyPI
v3.0.53
10,602 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
70 /100 Good
Development Activity 64
Maintenance 40
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
77 /100 Good
Architecture 84
Code Quality 82
Innovation 80
Learning Curve 62

prompt_toolkit is a pure-Python library for constructing rich, interactive command-line interfaces. It goes far beyond a GNU readline replacement: it supports syntax highlighting via Pygments lexers, advanced code completion, multi-line editing, both Emacs and Vi key bindings (including named registers and digraphs), mouse support, and auto-suggestions in the style of the fish shell. It powers well-known interactive tools including ptpython, the IPython shell, and pgcli, and its only runtime dependency is wcwidth, making it lightweight enough to embed in any CLI project.

What You Get

  • A full-screen and prompt-based application layer (prompt_toolkit.application, prompt_toolkit.shortcuts) for building anything from a single-line prompt to a full terminal UI
  • Pygments-backed syntax highlighting of input while typing, plus a styling system for themable terminal output
  • An extensible completion framework (prompt_toolkit.completion) supporting fuzzy, nested, and async completers for building rich autocomplete experiences
  • Both Emacs and Vi key-binding emulations, including advanced Vi features like named registers and digraphs
  • A widget toolkit (prompt_toolkit.widgets) with buttons, dialogs, text areas, and progress bars for building full-screen terminal UIs
  • Cross-platform input/output backends (prompt_toolkit.input, prompt_toolkit.output) abstracting terminal differences on Windows, Linux, and macOS

Common Use Cases

  • Building a REPL or interactive shell with syntax highlighting and history-aware autocompletion, as ptpython and IPython do
  • Adding a rich readline-style prompt with auto-suggestions and multi-line editing to a CLI tool, database client, or shell
  • Building a full-screen terminal dashboard or wizard using the widget toolkit and layout engine
  • Implementing Vi or Emacs-style modal editing inside a custom command-line tool

Under The Hood

Architecture The library is layered around an Application object (src/prompt_toolkit/application) that owns the event loop and ties together three concerns: a Layout tree (src/prompt_toolkit/layout) of Window/Container objects describing what’s on screen, a KeyBindings registry (src/prompt_toolkit/key_binding) mapping key sequences (Emacs- or Vi-mode) to handler functions, and an Output/Input pair (src/prompt_toolkit/output, src/prompt_toolkit/input) abstracting the actual terminal (VT100 escape codes on Unix, Win32 console API on Windows). Higher-level conveniences like prompt() in src/prompt_toolkit/shortcuts and the widgets package are built entirely on top of this same Application/Layout/KeyBindings core, so a single-line prompt and a full-screen TUI share one rendering pipeline. Tech Stack Pure Python 3.10+ with exactly one runtime dependency (wcwidth, for correct terminal-width computation of Unicode/CJK characters); Pygments is an optional integration for syntax highlighting rather than a hard dependency. Packaging uses a standard pyproject.toml/hatchling-style build with dependency groups for docs (Sphinx) and dev tooling. Code Quality tests/ contains 21 test files exercising the layout engine, key-binding dispatch, completion, regex-based lexers, and clipboard/history behavior; the project has a long single-maintainer commit history (Jonathan Slenders holds the vast majority of commits) with a broader contributor base handling incremental fixes, and CI runs via AppVeyor plus Codecov coverage tracking. Code is organized into clearly bounded subpackages (filters, lexers, completion, styles, formatted_text, eventloop) each with a narrow, well-documented responsibility. API Design The library explicitly advertises ‘no global state,’ and its top-level API mirrors that: sessions, applications, and key-binding registries are all explicit objects you construct and pass around rather than mutate implicitly, which makes the library composable but means newcomers must learn the Application/Layout/KeyBindings vocabulary before building anything beyond a basic prompt() call. Extensive docs and a gallery of real projects (ptpython, ipython, pgcli) built on the library offset that initial learning curve.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers