Search

Easily Create Progress Bars in Python

Fast, easy and elegant!


Easily Create Progress Bars in Python


After the post about how to create progress bars with C++, some people asked me if there was a tool for Python, and of course there are several!

The simplest and easiest to use is tqdm .

tqdm derives from the Arabic word taqaddum (تقدّم ), which can mean “progress” and is an abbreviation of “I love you so much” in Spanish (te quiero too).

With it you can quickly create smart progress bars - just wrap any iterable with tqdm and that’s it!


Installation

To insta is very simple, just have pip

And then use it, example:

pip install tqdm

If you have a problem with the installation, try only for your user, for example:

pip install tqdm --user

There is also the possibility to install from the development branch

pip install "git+https://github.com/tqdm/tqdm.git@devel#egg=tqdm"

Basic example

Now just import tqdm in your code and implement

vim progress.py

from tqdm import tqdm
from time import sleep
for i in tqdm(range(10000)):
    sleep(0.001)

And test:

python progress.py

The output will be animated, see part of the simplified animation:

███████████████████████████████████████████████████████████████████ 3034/10000 [00:03<00:08, 815.13it/s]

And there are still several ways to implement it, for example, directly from the prompt:

seq 9999999 | tqdm --bytes | toilet -l

Or with the parameters: --unit_scale and --total [N] combined:

seq 9999999 | tqdm --unit_scale --total 999999 | toilet -l

Show, huh?!

For more information, run:

tqdm --help

And visit the official website: https://tqdm.github.io/


python


Share



Comments