Tqdm

Create progress bars for loops

tqdm is a nice and easy way to create progress bars for your loops.
Trivia: tqdm means “progress” in Arabic (taqadum, تقدّم) and is an abbreviation for “I love you so much” in Spanish (te quiero demasiado).

Install

pip install tqdm

or

conda install tqdm

Basic usages

Import

in a Python script: from tqdm import tqdm
in Jupyter notebook: from tqdm.notebook import tqdm

To automatically choose between console or notebook versions: from tqdm.auto import tqdm

Simple loop

for i in tqdm(range(10000)):
    pass

76%|████████████████████████████         | 7568/10000 [00:33<00:10, 229.00it/s]

Wrap an iterator

with tqdm(range(10000), total=10000) as pbar:
    for n, i in enumerate(pbar):
        pass

Monitor values within the progress bar

You should avoid printing messages with an active tqdm progress bar since it can mess with the display. To monitor values throughout the iterations you can use set_postfix:

from time import sleep

with tqdm(range(10000), total=10000) as pbar:
    for n, i in enumerate(pbar):
        sleep(0.1)
        pbar.set_postfix({'n x i': f'{n*i}'})

17%|█▋        | 1675/10000 [00:20<01:40, 82.46it/s, n x i=2802276]

Documentation

https://tqdm.github.io/