Open In App
Related Articles

Progress Bars in Python

Improve Article
Save Article
Like Article

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.

Using tqdm

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. 


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

Output: python-tqdm1 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. 


from tqdm import tqdm
import time
for i in tqdm (range (101),
               ascii=False, ncols=75):

Output: python-tqdm-2

Using progressbar

How To Install

For command-line interface

pip install progressbar 
pip install progressbar2


It does everything the same as tqdm package, that is it decorates the iterable with the built-in widgets to make an animated progress bar or even a colorful one. Widgets are objects which display depending on the progress bar. However, the progress bar and the progress bar 2 packages have a lot of extra, useful methods than the tqdm package. For example, we can make an animated loading bar. 


import progressbar
import time
# Function to create
def animated_marker():
    widgets = ['Loading: ', progressbar.AnimatedMarker()]
    bar = progressbar.ProgressBar(widgets=widgets).start()
    for i in range(50):
# Driver's code


In progressbar.AnimatedMarker(), we can pass any sequence of characters to animate. The default arguments are ‘|/-\|’ Here’s another example using some of the commonly used widgets of the ProgressBar class. 


import time
import progressbar
widgets = [' [',
         progressbar.Timer(format= 'elapsed time: %(elapsed)s'),
         '] ',
           progressbar.Bar('*'),' (',
           progressbar.ETA(), ') ',
bar = progressbar.ProgressBar(max_value=200,
for i in range(200):

Output: python-progressbar

                        Using sys and time


  • Sys:

Functions and variables for modifying many elements of the Python runtime environment are available in the sys module.

The following code can be used to import this built-in module without having to install it first:

import sys
  • Time:

Accessing time in Python is made possible by the time module. It has capabilities like the ability to delay the execution of the application and the ability to get the current date and time. This module needs to be imported before we can start using its features.

This is an in-built module and need not be installed, it can be imported directly using the code:

import time
  • Random:

Python comes with a built-in module called Python Random that may be used to create random integers. Since they are not completely random, these numbers are pseudo-random. This module may be utilized to carry out random operations like generating random integers, printing a random value for a list or string, etc.

It is not necessary to install this built-in module because it may be imported directly using the following code:

import random



import sys,time,random
def progressBar(count_value, total, suffix=''):
    bar_length = 100
    filled_up_Length = int(round(bar_length* count_value / float(total)))
    percentage = round(100.0 * count_value/float(total),1)
    bar = '=' * filled_up_Length + '-' * (bar_length - filled_up_Length)
    sys.stdout.write('[%s] %s%s ...%s\r' %(bar, percentage, '%', suffix))
for i in range(11):
#This code is Contributed by PL VISHNUPPRIYAN


Output in Terminal Window

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 10 Jan, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials