Fundamentals 6 min read

Using progress and tqdm Libraries to Create Progress Bars in Python

This article introduces the Python progress‑bar libraries progress and tqdm, explains how to install them, demonstrates basic and advanced usage—including custom styles, pausing, and multithreaded progress bars—with complete code examples for each scenario.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Using progress and tqdm Libraries to Create Progress Bars in Python

Progress bars display the execution progress of long‑running code, improving readability and aiding debugging, especially in data‑science and deep‑learning tasks.

The two popular Python libraries covered are progress and tqdm . Both can be installed via pip install progress and pip install tqdm , then imported with from progress.bar import Bar and from tqdm import tqdm .

Basic usage

Using progress :

from progress.bar import Bar
import time
bar = Bar('Processing', max=20)
for i in range(20):
    time.sleep(0.5)
    bar.next()
bar.finish()

Using tqdm :

from tqdm import tqdm
import time
for i in tqdm(range(20)):
    time.sleep(0.5)

Advanced usage

Customizing the appearance of a tqdm bar:

from tqdm import tqdm
import time
for i in tqdm(range(20), bar_format='{l_bar}{bar:20}{r_bar}{bar:-10b}'):
    time.sleep(0.5)

Pausing and resuming:

from tqdm import tqdm
import time
for i in tqdm(range(20)):
    time.sleep(0.5)
    if i == 10:
        tqdm.write('Paused, press Enter to continue.')
        input()

Using multiple progress bars in a multithreaded environment:

from tqdm import tqdm
import threading
import time

def worker():
    for i in tqdm(range(20)):
        time.sleep(0.1)

threads = []
for i in range(5):
    t = threading.Thread(target=worker)
    threads.append(t)
    t.start()
for t in threads:
    t.join()

Conclusion

The progress and tqdm libraries provide simple ways to add attractive, functional progress bars to Python programs, supporting basic displays, custom formatting, pause/resume control, and multithreaded execution, thereby enhancing code readability and debugging efficiency.

multithreadingCustomizationprogress bartqdmProgress
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

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.