How to use progressbar In Python

How To Install

For command-line interface

pip install progressbar 
(or)
pip install progressbar2

Working

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. 

Python3




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):
        time.sleep(0.1)
        bar.update(i)
         
# Driver's code
animated_marker()


Output:

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. 

Python3




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


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

...