Enhance tqdm progress bars by assigning tags and colors to iterations.
Project description
tqdm-tag
Color-code individual items in a tqdm progress bar by tagging them with a status.
tqdm-tag extends tqdm so you can call pbar.warn() or pbar.error() on any item inside your loop. The corresponding segment of the progress bar fills with that tag's color, giving you an at-a-glance overview of where issues occurred — without waiting for the loop to finish.
Top: plain tqdm (monochrome). Bottom: tqdm-tag coloring each processed item by outcome.
Installation
pip install tqdm-tag
Usage
TqdmErrorTag is a drop-in replacement for tqdm — swap the class name and you're done. Call .warn() or .error() on any item to color that segment of the bar:
from tqdm_tag import TqdmErrorTag
pbar = TqdmErrorTag(range(100), legend=True, desc="Processing")
for item in pbar:
result = process(item)
if result.has_warning: pbar.warn()
if result.has_error: pbar.error()
With legend=True, a live second line below the bar shows running counts:
Processing: 73%|████████████████████ | 73/100 [00:03<00:01, 12.5it/s]
■ warn: 4 ■ error: 1
Custom tags with TqdmTag
For full control, use TqdmTag with Tag objects. Each Tag groups name, color, and an optional status integer (auto-assigned if omitted):
from tqdm_tag import Tag, TqdmTag
pbar = TqdmTag(
range(100),
tags=[Tag("warn", color="yellow"), Tag("error", color="red")],
legend=True,
)
for i in pbar:
if i == 10: pbar.tag("warn") # reference by name string
if i == 80: pbar.tag("error")
Add tags on the fly
Pass a Tag object directly to .tag() to register and apply it in one call. Subsequent calls can use the name string:
from tqdm_tag import Tag, TqdmTag
pbar = TqdmTag(range(100))
for i in pbar:
if i == 10: pbar.tag(Tag("warn", color="yellow")) # registers + applies
if i == 30: pbar.tag("warn") # reuse by name
if i == 80: pbar.tag(Tag("error", color="red"))
Turn the whole bar green on success
import time
from tqdm_tag import TqdmTag
items = range(50)
pbar = TqdmTag(items, colour="red")
for i in pbar:
time.sleep(0.05)
if i == len(items) - 1:
pbar.tag("default", color="green")
Customize the legend
Tags in the legend are ordered by status value. Pass a legend_format callable to take full control — it receives tag_counts (dict of name → count) and tag_to_color (dict of name → color):
def my_legend(counts, colors):
return " ".join(f"[{k.upper()}={v}]" for k, v in counts.items())
pbar = TqdmErrorTag(range(100), legend=True, legend_format=my_legend)
Reduce operation for dense bars
When the terminal is narrow, multiple items share one bar segment. Use reduce_op to control which status wins, and reduce_ignore_default to skip untagged items:
from tqdm_tag import Tag, TqdmTag
pbar = TqdmTag(
range(100),
tags=[Tag("warn", color="yellow", status=1), Tag("error", color="red", status=2)],
reduce_op=max, # highest-severity status wins
reduce_ignore_default=True, # don't let untagged items dilute the color
)
for i in pbar:
if i % 10 == 1: pbar.tag("warn")
if i % 10 == 2: pbar.tag("error")
API
| Class | Description |
|---|---|
TqdmErrorTag |
Drop-in replacement with pre-wired warn / error tags and .warn() / .error() helpers |
TqdmTag |
Core class for fully custom tags |
Tag |
Dataclass grouping a tag's name, color, and status |
ColoredBar |
Internal Bar subclass that renders ANSI-colored segments |
Full API reference: tqdm-tag.readthedocs.io
License
MIT © Colin Moldenhauer
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tqdm_tag-0.4.2.tar.gz.
File metadata
- Download URL: tqdm_tag-0.4.2.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7e778ad78aa8cb792b9053ca2e67790db3566005e9aec3c6f0f5c8499bbf1b7
|
|
| MD5 |
7796f01f45cbaa6504c214bc89f89681
|
|
| BLAKE2b-256 |
c0fc4fff8cecc87a472777ee5f29478e2baae1543eae50b840edbcbd25dc79d3
|
Provenance
The following attestation bundles were made for tqdm_tag-0.4.2.tar.gz:
Publisher:
publish.yml on ColinMoldenhauer/tqdm-tag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tqdm_tag-0.4.2.tar.gz -
Subject digest:
b7e778ad78aa8cb792b9053ca2e67790db3566005e9aec3c6f0f5c8499bbf1b7 - Sigstore transparency entry: 1690142054
- Sigstore integration time:
-
Permalink:
ColinMoldenhauer/tqdm-tag@ade493b459847eaeb8a7e9ebfff8d9a97851495b -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/ColinMoldenhauer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ade493b459847eaeb8a7e9ebfff8d9a97851495b -
Trigger Event:
push
-
Statement type:
File details
Details for the file tqdm_tag-0.4.2-py3-none-any.whl.
File metadata
- Download URL: tqdm_tag-0.4.2-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe6ac1164c85e248820a031f18f77429126b86d40ac7d6256c3c6e7d6c184720
|
|
| MD5 |
c292238c48ca5ecb9a9f2173b6cc8dc5
|
|
| BLAKE2b-256 |
d35e091d69d954b113550dca497ab29ac5393561bc563a0faadc4fe9f23a4f02
|
Provenance
The following attestation bundles were made for tqdm_tag-0.4.2-py3-none-any.whl:
Publisher:
publish.yml on ColinMoldenhauer/tqdm-tag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tqdm_tag-0.4.2-py3-none-any.whl -
Subject digest:
fe6ac1164c85e248820a031f18f77429126b86d40ac7d6256c3c6e7d6c184720 - Sigstore transparency entry: 1690142171
- Sigstore integration time:
-
Permalink:
ColinMoldenhauer/tqdm-tag@ade493b459847eaeb8a7e9ebfff8d9a97851495b -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/ColinMoldenhauer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ade493b459847eaeb8a7e9ebfff8d9a97851495b -
Trigger Event:
push
-
Statement type: