Python progress bar tqdm
In this article, you will learn how to show a progress bar of any data file using the Python programming language.
The progress bar assists the user by visualising the progression of an extended computer operation, such as a download, file transfer, or installation. Without this, it will be very hard to estimate how many files have been uploaded in the background or what process is happening in the background. This becomes very confusing if the user uploads a large file, because they will have to wait a long time without any current status. So it is very helpful to the user if the developer provides functionality to show the uploaded file progress bar in percentage.
There are several ways to add a progress bar in Python, but here we are using the tqdm module. tqdm derives from the Arabic word taqaddum which means progress. The tqdm module gives a console kind of progress bar for our processes. It utilises keen calculations to anticipate the remaining time and to skip superfluous cycle shows, which allows for a negligible overhead in most cases. A tqdm progress bar not only shows you how much time has elapsed, but also shows the estimated time remaining for the iterable.
Installation of tqdm module
The following command instals the tqdm module using the PIP tool-
pip install tqdm
Use the following command, if you are using Python3-
pip3 install tqdm
Python progress bar example
It is very easy to use the tqdm progress bar module. We simply need to add your code between tqdm() in the wake of bringing in the library in our code. You must ensure that the code you place in the middle of the tqdm() work is iterable or it will not work. In the given example, we use the tqdm() function on a simple program with a for loop.
from tqdm import tqdm
for i in tqdm (range (100), desc="Loading..."):
pass
Output of the above code - 
The tqdm() function has the following syntax-
tqdm (self, iterable, desc= "progress text", total=None, file=None)
Here, iterable is to be decorated with a progressbar. We can leave this blank to manually manage the updates. The total specifies the total number of expected iterations, if not specified already or needs modification. The desc specifies the description of the progress bar, while the file specifies where to output the progress messages.
Add color to Python tqdm progress bar
If you don’t find the idea of adding colours to progress bars distracting, then this example might be for you. The tqdm can work with colorama, a simple cross-platform coloured terminal text in Python. The following example demonstrates this.
from tqdm import trange
from colorama import Fore
# cross-platform colored terminal text
color_bars = [Fore.RED,
Fore.GREEN,
Fore.BLUE,
Fore.MAGENTA,
Fore.YELLOW,
Fore.CYAN,
Fore.WHITE]
for color in color_bars:
for i in trange(int(7e7),
bar_format="{l_bar}%s{bar}%s{r_bar}" % (color, Fore.RESET)):
pass
Output of the above code -

Related Articles
Count consonants in a string Python
Python program to add two numbers
Convert list to dictionary Python
Convert array to list Python
numpy dot product
Python weather api
glob in Python
Python heap implementation
zip function in Python
Remove last element from list Python
Check if list is empty Python
Remove element from list Python
Python split multiple delimiters
Python loop through list
Python iterate list with index
Python add list to list
Python random choice
Python dict inside list
Remove character from string Python
Python raise keyword