Python Tqdm Module
tqdm (read as "taqadum", meaning "progress" in Arabic) is a fast, extensible progress bar for Python and CLI. It allows you to wrap any iterable with a smart progress meter.
Installation
pip install tqdm
Importing the Module
from tqdm import tqdm
import time
Basic Usage
Wrap any iterable with tqdm().
for i in tqdm(range(100)):
time.sleep(0.01)
Working with Lists
my_list = ["a", "b", "c", "d"]
for item in tqdm(my_list):
time.sleep(0.5)
Manual Control
If you are not using a loop or need manual updates (e.g., downloading a file in chunks).
with tqdm(total=100) as pbar:
for i in range(10):
time.sleep(0.1)
pbar.update(10) # Increment by 10
Customizing the Bar
You can add descriptions and postfix information.
pbar = tqdm(range(100))
for i in pbar:
pbar.set_description(f"Processing {i}")
time.sleep(0.01)
Pandas Integration
tqdm can integrate with Pandas apply functions.
import pandas as pd
import numpy as np
from tqdm import tqdm
tqdm.pandas()
df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
# Use progress_apply instead of apply
df.progress_apply(lambda x: x**2)