prompt_toolkit
A pure-Python library for building powerful interactive command-line applications
Repository Health
Technical Analysis
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.
Used by 10 apps in this directory
argilla
AI Development · Data Engineering
Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.
AutoGPT
Automation · Productivity · AI Assistants
Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.
Beta9
Developer Tools · AI Development · Data Engineering
Run AI workloads at scale with a Pythonic serverless runtime that handles GPU inference, background jobs, and sandboxes with zero infrastructure overhead.
deepagents
AI Agents · AI Development
The batteries-included Python agent harness — planning, sub-agents, filesystem, shell, memory, and skills bundled in, built on LangGraph.
knowhere
AI Development · Developer Tools
Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.
OpenBB
Databases · Analytics · Invoicing Finance
The AI Workspace for Finance: Connect Data, Run AI Agents, Build Analytics
OpenHands
AI Code Assistants · AI Development
The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.
OpenViking
Databases · AI Development
An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.
Rasa Open Source
AI Assistants · AI Development
Rasa Open Source is a Python machine learning framework for building contextual, multi-turn chatbots and voice assistants that understand natural language and maintain conversation state.