tqdm

Simple progress bars for iterables

Created: July 7th 2019
Updated: December 7th 2019
Connect with us on
image
image

tqdm is a python module that allows you to create progress bars. It works by wrapping an iterable in the tqdm object, more info can be found in the readme from the source code

Definitions

Some terms to help you navigate the post

TQDM

A module that allows you to create progress bars for iterables in python.

Usage

Requirements

For this demo you will need a few things, i've outlined the requirements below and how to set them up:

  • TQDM: to get tqdm you can either use pip install tqdm or in the folder with this readme run pip install -r requirements.txt

Real World Applications

This module is incredibly useful for scripts that have any long iteration processes. For example if you are scraping contents from an HTML table on a webpage that has a few hundred entries adding a progress bar let's users (including you) know that the script/program hasn't crashed and is just taking a while to process.

Files

requirements.txt

tqdm

tqdm_demo.py

from tqdm import tqdm # The module relies on a class called tqdm inside the module
import time # Used to delay iteration to make the progress bar more easily visible

# Un-fortmatted tqdm progress bar
print("Here is your standard tqdm bar:")

for iteration in tqdm(range(10)):
    time.sleep(.3)

# Example of a formatted tqdm bar
print("Here is a custom formatted tqdm bar:")
iterable = tqdm(range(100)) # Setting iterable wrapped in tqdm as a variable

for amount_complete in iterable: # This demo is based on https://github.com/tqdm/tqdm#iterable-based
    time.sleep(0.25)
    iterable.set_description(f"Currently at %{amount_complete}") # Allows you to overwrite the default printing style provided by tqdm

Thank you for your support!

Be sure to share the post if it was helpful!