Member-only story
Python
5 Levels of Using tqdm in Python: Build Elegant Progress Bars
A comprehensive guide with practical examples
When you’re running long loops, processing large datasets, or waiting on I/O-bound tasks, it’s easy to lose track of what’s happening. Without feedback, users (or even you as a developer) may assume the program has frozen or failed.
That’s where a progress bar comes in.
tqdm
(from the Arabic word "taqaddum", meaning "progress") is one of the most powerful and widely used progress bar libraries in Python.
In this hands-on tutorial, you’ll explore 5 progressive levels of mastering tqdm
, from simple loops to advanced use cases involving asynchronous programming.
Let’s start the journey now.
Level 1: Basic Progress Bar for Iterables
The simplest way to use tqdm
is just to wrap your iterable with it.
For example, the following code simulates processing customer orders in an e-commerce system and tracking the progress with tqdm
:
import time
from tqdm import tqdm
# Simulate customer order data
customer_orders = [
{"id": 1, "customer": "Yang Zhou", "amount": 299.99},
{"id": 2, "customer": "Bob"…