Creating a Python Script to demonstrate Rich
Now, since we have the rich package installed in the virtual environment, we can use the rich package in a python script and leverage its formatting and logging styles in the terminal I/O. We’ll first create a hello word script in python and demonstrate a few other functions and operators provided by the rich package.
Python3
from rich import print print ( "Hello, [bold green]Geeks[/bold green]!" ) |
Here, we are importing a function called print from the rich package which we just installed. The print function is different from the regular print function provided by python. Though it’s technically serving the same purpose it can do a lot more than a normal print function. In the above example, the print function has a few things written which are interpreted by python as a formatting style like the [bold green] and [/bold green].
These two tags simply represent the start and end of the styling provided in the square brackets. The styles provided in this example are bold and green. You can choose a few options for the decoration of the text as provided below:
The colors can be chosen from the list provided in the docs with this link, the colors are 256 Standard colors along with a CSS-styled color format. The decoration like bold, italics, underlined, strike, reverse, etc. can be provided in the list from the documentation.
Installing and Using Rich Package in Python
In this article, We are going to learn how to install and use rich packages in Python.
RIch is a python package for creating some awesome terminal formatting and logging. It has several features and functions that can make your application look nicer and even add a new look to your CLI application. We will be understanding the process of installing and basic usage of the RICH package in Python in this article.