Fundamentals 3 min read

Using tqdm to Display Real-Time Progress Bars in Python

This tutorial introduces the Python tqdm library, shows how to install it, explains its three usage modes, and provides clear code examples for displaying real-time progress bars during long loops, helping developers monitor elapsed time effectively.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Using tqdm to Display Real-Time Progress Bars in Python

1. Tool

The tutorial introduces tqdm , a Python progress‑bar library that can wrap any iterator to provide a fast, extensible visual indication of loop progress.

2. Installation

Install the library via pip:

$ pip install tqdm

3. Usage of tqdm

tqdm offers three main ways to control progress display: automatic control, manual control, and script/command‑line usage.

4. Example 1 – Passing an Iterable

Import the library and use tqdm to wrap a range object, sleeping 0.1 s each iteration to simulate work. The progress bar advances every 0.1 s, resulting in a total duration of 60 seconds.

import time
from tqdm import *

for i in tqdm(range(10 * 60)):
    time.sleep(0.1)    # progress bar advances every 0.1 s, total time = 60 s

5. Example 2 – Using trange

trange(i) is a shorthand for tqdm(range(i)) . The example demonstrates the same 60‑second loop with trange .

import time
from tqdm import trange

for i in trange(10 * 60):
    # do something
    time.sleep(0.1)

Both examples can be adapted by replacing the constant 60 with a variable to set the desired number of seconds for the progress bar.

For further exploration, refer to the official GitHub repository: https://github.com/tqdm/tqdm .

cliPythontutorialprogress bartqdm
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.