/ Command-line Tools

A library for building powerful interactive command lines

A library for building powerful interactive command lines

Python Prompt Toolkit

prompt_toolkit is a library for building powerful interactive command lines and terminal applications in Python.



ptpython is an interactive Python Shell, build on top of prompt_toolkit.

prompt_toolkit features
prompt_toolkit could be a replacement for GNU readline, but it can be much more than that.

Some features:

Pure Python.

  • Syntax highlighting of the input while typing. (For instance, with a Pygments lexer.)
  • Multi-line input editing.
  • Advanced code completion.
  • Both Emacs and Vi key bindings. (Similar to readline.)
  • Even some advanced Vi functionality, like named registers and digraphs.
  • Reverse and forward incremental search.
  • Runs on all Python versions from 2.6 up to 3.5.
  • Works well with Unicode double width characters. (Chinese input.)
  • Selecting text for copy/paste. (Both Emacs and Vi style.)
  • Support for bracketed paste.
  • Mouse support for cursor positioning and scrolling.
  • Auto suggestions. (Like fish shell.)
  • Multiple input buffers.
  • No global state.
  • Lightweight, the only dependencies are Pygments, six and wcwidth.
  • Runs on Linux, OS X, FreeBSD, OpenBSD and Windows systems.
  • And much more...



pip install prompt_toolkit

For Conda, do:


    conda install -c https://conda.anaconda.org/conda-forge prompt_toolkit

Getting started

The most simple example of the library would look like this:

.. code:: python

from prompt_toolkit import prompt

if __name__ == '__main__':
    answer = prompt('Give me some input: ')
    print('You said: %s' % answer)

For more complex examples, have a look in the examples directory. All
examples are chosen to demonstrate only one thing. Also, don't be afraid to
look at the source code. The implementation of the prompt function could be
a good start.

Note for Python 2: all strings are expected to be unicode strings. So, either
put a small u in front of every string or put from __future__ import unicode_literals at the start of the above example.