Python rich – Create a progress bar

In this post we will be creating a Python script that will display a progress bar 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 implement a progress bar that will increment each time the for loop is iterated. Our delay would be replaced by some function or task carried out.

import time
from rich.progress import track

for i in track(range(10), description="[green]loading..."):
    time.sleep(1)

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

Python progress bar using rich library

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

Leave a Reply