How to use tqdm In Python

What It Does

It wraps an iterable with the tqdm to decorate it with the methods built-in with tqdm and make a loading bar. This will take the users’ mind off of how long the process is taking to complete.

How To Use

All we need to do is, install the tqdm package by typing this line in your terminal and start writing the code.

->pip install tqdm

And type this code in your editor. 

Python3




from tqdm import tqdm
 
for i in tqdm (range (100), desc="Loading..."):
    pass


Output: This gives a very fast loading bar because there’s nothing in the loop., you can replace the pass keyword with whatever work you want to do in the for loop. 

Python3




from tqdm import tqdm
import time
 
 
for i in tqdm (range (101),
               desc="Loading…",
               ascii=False, ncols=75):
    time.sleep(0.01)
     
print("Complete.")


Output:

Progress Bars in Python

Understandably, we get a little impatient when we do not know how much time a process is going to take, for example, a for loop or a file downloading or an application starting up. To distract us from that we were given the libraries tqdm and progressbar in Python language which allows us to give a visual illustration of the process completion time using a progress bar. Loading bars are often seen on game screens as the resources required for the game to run are being acquired to the main memory.

Similar Reads

Using tqdm

What It Does...

Using progressbar

...

Using sys and time

...