Skip to main content

Library for building powerful interactive command lines in Python

Project description

(Work in progress. Many things work, but APIs can change.)

prompt_toolkit is a Library for building powerful interactive command lines in Python. It ships with a nice interative Python shell built on top of the library.

prompt_toolkit can be a replacement for readline.

Features:

  • Pure Python.

  • Syntax highlighting of the input while typing. (For instance, with a Pygments lexer.)

  • Multiline input editing

  • Advanced code completion

  • Both Emacs and Vi keybindings (Similar to readline)

  • Reverse and forward incremental search

  • Both Python 3 and Python 2.7 support

  • Works well with Unicode double width characters. (Chinese input.)

  • Code written with love.

Limitations:

  • Only for vt100-compatible terminals. (Actually, all terminals in OS X and Linux systems are VT100 compatible the days, so that should not be an issue. There is no Windows support, however.)

Installation

pip install prompt-toolkit

The Python repl

Run ptpython to get an interactive Python prompt with syntaxt highlighting, code completion, etc…

docs/images/ptpython-screenshot.png

If you prefer to have Vi keybindings (which currently are more completely implemented than the Emacs bindings), run ptpython --vi.

If you want to embed the repl inside your application at one point, do:

from prompt_toolkit.contrib.repl import embed
embed(globals(), locals(), vi_mode=False, history_filename=None)

Autocompletion

Tab and shift+tab complete the input. (Thanks to the Jedi autocompletion library.) In Vi-mode, you can also use Ctrl+N and Ctrl+P.

docs/images/ptpython-complete-menu.png

Multiline editing

Usually, multiline editing mode will automatically turn on when you press enter after a colon, however you can always turn it on by pressing F7.

To execute the input in multiline mode, you can either press Alt+Enter, or Esc followed by Enter. (If you want the first to work in the OS X terminal, you have to check the “Use option as meta key” checkbox in your terminal settings.)

You love IPython?

Run ptipython (prompt_toolkit - IPython), to get a nice interactive shell with all the power that IPython has to offer, like magic functions and shell integration.

docs/images/ipython-integration.png

Using as a library

This is a library which allows you to build highly customizable input prompts. Every step (from key bindings, to line behaviour until the renderer can be customized.)

A simple example looks like this:

from prompt_toolkit import CommandLine, AbortAction
from prompt_toolkit.line import Exit

def main():
    # Create CommandLine instance
    cli = CommandLine()

    try:
        while True:
            code_obj = cli.read_input(on_exit=AbortAction.RAISE_EXCEPTION)
            print('You said: ' + code_obj.text)

    except Exit: # Quit on Ctrl-D keypress
        return

if __name__ == '__main__':
    main()

Project details


Release history Release notifications | RSS feed

This version

0.6

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prompt_toolkit-0.6.tar.gz (51.5 kB view details)

Uploaded Source

File details

Details for the file prompt_toolkit-0.6.tar.gz.

File metadata

  • Download URL: prompt_toolkit-0.6.tar.gz
  • Upload date:
  • Size: 51.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for prompt_toolkit-0.6.tar.gz
Algorithm Hash digest
SHA256 aba9198ece331e4d39e545860b0415c8c485ae976b524289f9a3b62abbe548bf
MD5 4c54d52a140c2fbc95631f9e63b74b65
BLAKE2b-256 19bd0c2df2a6268a67b3b53bf0fdfd161d7423c909d433abf584fc4ada70d799

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page