Skip to content

#298: Fancy Progress Bars With Alive-Progress

Tqdm from last week's post is for me the go-to helper when I need a progress bar. However, sometimes we need something especially fancy and for that purpose it is good to know about alive-progress.

Installation

We can install the alive-progress package with this command:

pip install alive-progress

What do we mean with fancy?

After the installation succeeded, we can use the built-in demo application to see the many options we get for progress bars:

1
2
3
from alive_progress.styles import showtime

showtime()

The demo shows the many possibilities of alive-progress at once.

This demo doubles as documentation and show us how the progress bars look in action.

The basic progress bar is still possible

For a minimalistic progress bar, we can use this code:

1
2
3
4
5
6
7
8
9
from alive_progress import alive_bar
import time

x = 100

with alive_bar(total=x, spinner="circles") as bar:
    for i in range(x):
        time.sleep(.05)
        bar()

When we run the code, we get a basic (and boring) progress bar:

The plain progress bar does the job.

Working with unknown sizes

If we do not know the total size of our iteratable, we can set total=None. If we do so, the options of the progress bar change and we can use a unknown parameter for the bar style:

1
2
3
4
5
6
7
8
9
from alive_progress import alive_bar
import time

x = 100

with alive_bar(total=None, spinner="waves", unknown="flowers", bar="checks") as bar:
    for i in range(x):
        time.sleep(.05)
        bar()

If we run the code, we get a more fancy progress bar:

We now have flowers, waves, and checkmarks in our progress bar.

Downsides

As much fun alive-progress is, there is one big downside in my opinion: the documentation. While it is possible to get the progress bar behaviour you want, it is a lot of experimentation to find the right options. I hope this point will be improved in the future, then it would make this little helper so much more useful.

Conclusion

With alive-progress we get a highly customisable progress bar. If you figure out how to use it, you can get the styles exactly the way you need them. If all you need is a progress bar, I suggest you go with tqdm. I find that package much better documented and features like the support for Pandas is more important for me than using flowers.