Rich library
Spice up your Python console applications
Matt Holder demonstrates how to use the Python Rich library to add formatting to your console applications.
RICH
Credit: https://github.com/Textualize/rich
OUR EXPERT
Matt Holder has been a fan of the open source methodology for over two decades and uses Linux and other tools where possible. In his spare time, he enjoys listening to music and reading.
When writing terminal apps, it would sometimes be useful W to emphasise information, to make the user aware of certain important or dangerous operations. The Rich library provides console rendering for many things, such as the printing of emojis, coloured text, rendering of tabular information and markdown, collection of information from the user – including allowing from a selection of choices as well as progress bars and spinners, which is helpful in denoting long-running information. Another useful feature of the library is the ability to export the console output to a file – when exporting as HTML, formatting is included. The library can be used on Windows, Mac and Linux, and it tries to automatically determine the colour and other capabilities of the OS’s terminal.
Before we can use the library, we must install it. In a terminal enter pip install rich . Now, open a terminal and enter the following:
$ python
from rich import print
print(“[red underline]:thumbs_up: hello world”)