Programming, Python

Add Color and Style to your python terminal output.

It is boring to see black and white text in the console output when you are using such a beautiful language like python.

Recently, I found a python library which formats the console output and gives it style and color to enhance readability and user experience.

Although programmers are already used to seeing monotonous console screen who doesn’t like like colors and fancy stuff.

Features
Rich Library in python

The preview already looks tempting and useful.

Let’s install and dive into what all the library has to offer.

To install the Rich Library you can execute the following command :

pip install rich

Installing rich library

After installing the library you can test the install by executing the command:

python -m rich

Well this does not look same as the preview because windows cmd and powershell is limited to 8 bit color and does not support language and emoji functionality.

So I installed the “new windows console“.

New windows console running rich python

Well this looks great just like the preview shared by the author of the “Rich Library”

Print Rich Formatted text in console

from rich import print

print(“Hello, [bold magenta]World[/bold magenta]!”, “:vampire:”, locals())

Rich Formatted text in console

Rich Inspect objects

from rich import

inspect inspect(str, methods=True)

Rich Inspect Object

Rich Logging in python

rich logging

Emojis in Console

from rich.console

import Console console = Console()

console.print(“:smiley: :vampire: :pile_of_poo: :thumbs_up: :raccoon:”)

Rich Emoji in console

Progress bar in Console

Loading spinner in Console

Traceback in python

Formatted rich traceback in python

The Rich library is full of features to customize the console out put and make it stylish and presentable even.

So now you can show you application output without designing a pretty GUI.

For more info and use cases visit the Rich Github. Don’t forget to give a star for the developer.


Thank you for reading, Happy Learning, drop your suggestion in the comments.

Feel free to follow us on Youtube , Linked In , Instagram

0 0 vote
Article Rating