DEV Community

Cover image for Quick Progress Bars in python using TQDM
Waylon Walker
Waylon Walker

Posted on

Quick Progress Bars in python using TQDM

tqdm is one of my favorite general purpose utility libraries in python. It allows me to see progress of multipart processes as they happen. I really like this for when I am developing something that takes some amount of time and I am unsure of performance. It allows me to be patient when the process is going well and will finish in sufficient time, and allows me to 💥 kill it and find a way to make it perform better if it will not finish in sufficient time.

Quick aside, this is a crosspost from my personal blog https://waylonwalker.com/blog/quick-progress-bars-in-python-using-tqdm/

Alt Text

for more gifs like these follow me on twitter @waylonwalker

Add a simple Progress bar!

from tqdm import tqdm
from time import sleep

for i in tqdm(range(10)):
    sleep(1)
Enter fullscreen mode Exit fullscreen mode

convenience

TQDM also has a convenience function called trange that wraps the range function with a tqdm progress bar automatically.

from tqdm import trange
from time import sleep

for i in trange(range(10)):
    sleep(1)
Enter fullscreen mode Exit fullscreen mode

notebook support

There is also notebook support. If you are bouncing between ipython and jupyter I recomend importing from the auto module.

from tqdm.auto import tqdm
from time import sleep

for i in tqdm(range(10)):
    sleep(1)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)