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.
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
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“.
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 Inspect objects
from rich import
inspect inspect(str, methods=True)
Rich Logging in python
from rich.console import Console console = Console() test_data = [ {"jsonrpc": "2.0", "method": "sum", "params": [None, 1, 2, 4, False, True], "id": "1",}, {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]}, {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": "2"}, ] def test_log(): enabled = False context = { "foo": "bar", } movies = ["Deadpool", "Rise of the Skywalker"] console.log("Hello from", console, "!") console.log(test_data, log_locals=True) test_log()
Emojis in Console
from rich.console
import Console console = Console()
console.print(“:smiley: :vampire: :pile_of_poo: :thumbs_up: :raccoon:”)
Progress bar in Console
Loading spinner in Console
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.
Some Important links
Start learning python for free [Codecademy] [DataCamp]
Host your web app [DigitalOcean]
Learn a new Skill [SkillShare] Free one-month trail
Learn Product Design UI/ UX [Skill share] Free one-month trial
Register your .com domain name [Namecheap]
Get certification from top universities [Coursera]
Python for Everybody [Getting started with python]
Google-certified Python Course Crash Course in python
A VPN to stay anonymous & secure on web [AtlasVPN]
I may earn a small commission if you purchase the product from my links. This is one of the ways you can support this blog. The little commision we earn helps us bear the cost of hosting, paying for tools, and making new content. Thank you for your support