Wonderful Python Libraries series Nº 1 :: Prompt Toolkit

Today I start a new series of posts with my favorite Python libraries. I’ll share with you those that, I think, is most interesting.

In this post, I’ll present the library: Prompt Toolkit.

If you like CLI and terminals for writing your tools, You’ll like this library.

https://python-prompt-toolkit.readthedocs.io/en/master/index.html

With Prompt toolkit, you can create a rich console UI. Some of their features are:

  • Integrated auto-completion and auto-suggestion.
  • Integrated syntax highlighting support.
  • Integrated session history.
  • Key binding
  • Ncurses abstraction in Python.
  • Real-time progress bars with ncurses.
  • Parallel progress bars.
  • Create full-screen console apps.
  • Hooks.
  • Asyncio support.
  • Deadline support.
  • And more!

Creating a powerful REPL is straightforward. You can add syntax highlighting in the prompt in real time! Just great.

from pygments.lexers.html import HtmlLexer
from prompt_toolkit.shortcuts import prompt
from prompt_toolkit.lexers import PygmentsLexer

text = prompt('Hi Medium! Enter HTML: ', lexer=PygmentsLexer(HtmlLexer))
print('You wrote: %s' % text)

With Prompt toolkit, you can do excellent command line interfaces without the need to write ncurses code. It has shortcuts for creating dialogs, checkboxes, radio boxes, and more.

Here is an easy example:

from prompt_toolkit.shortcuts import radiolist_dialog

result = radiolist_dialog(
title="Hi Medium!",
text="What's your favorite IDE?",
values=[
("pycharm", "PyCharm"),
("vscode", "Vistual Studio Code"),
("wingide", "WingIDE")
]
).run()

I recommend you to visit their Gallery section on its website:

You can find great demos, even a VIM clone!

--

--

REST API Cybersecurity and Hacking & Python Architect. +100 GitHub projects. Speaker

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
cr0hn

REST API Cybersecurity and Hacking & Python Architect. +100 GitHub projects. Speaker