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:
If you like CLI and terminals for writing your tools, You’ll like this library.
This library, in a few words
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.
- Asyncio support.
- Deadline support.
- And more!
A REPL with steroids
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)
Ncurses dialogs and more
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(
text="What's your favorite IDE?",
("vscode", "Vistual Studio Code"),
I recommend you to visit their Gallery section on its website:
You can find great demos, even a VIM clone!