Python rich – Print coloured text

In this post we will be creating a Python script that will print coloured text whilst running. To do this we will be using the ‘rich’ library which allows us to aesthetically pleasing command line applications. The library is very useful whereby it allows formatting to many elements of output.

To install the rich library run the following command.

pip install rich

See the snippet of Python code below where we print coloured text. For a list of the standard colours available click here.

from rich import print as rprint


rprint("[bright_magenta] Welcome to Sciptopia [bright_magenta]")
rprint("[bright_blue] Welcome to Sciptopia [bright_blue]")
rprint("[bright_green] Welcome to Sciptopia [bright_green]")

An image of what this would look like whilst running can be seen below.

Print coloured text in Python using the rich library.

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply