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.tag("warn") or pbar.tag("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
TqdmTag is a drop-in replacement for tqdm. The only addition is the .tag(name) call:
from tqdm_tag import TqdmTag
pbar = TqdmTag(
range(100),
tag_to_status={"warn": 1, "error": 2},
tag_to_color={"warn": "yellow", "error": "red"},
)
for item in pbar:
result = process(item)
if result.has_warning:
pbar.tag("warn")
if result.has_error:
pbar.tag("error")
Define tags upfront
Pass tag_to_status and tag_to_color at construction time (integer statuses decide which color wins when a bar segment contains multiple items):
from tqdm_tag import TqdmTag
pbar = TqdmTag(
range(100),
tag_to_status={"warn": 1, "error": 2},
tag_to_color={"warn": "yellow", "error": "red"},
)
for i in pbar:
if i == 10: pbar.tag("warn")
if i == 80: pbar.tag("error")
Add tags on the fly
Omit tag_to_status/tag_to_color and pass a color directly to .tag() — new tags are registered automatically:
from tqdm_tag import TqdmTag
pbar = TqdmTag(range(100))
for i in pbar:
if i == 10: pbar.tag("warn", color="yellow")
if i == 30: pbar.tag("warn") # reuse tag (no color needed)
if i == 80: pbar.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")
Pre-configured error class
TqdmErrorTag ships with warn (yellow) and error (red) already wired up:
from tqdm_tag import TqdmErrorTag
pbar = TqdmErrorTag(range(100))
for i in pbar:
if i % 20 == 0: pbar.warn()
if i == 95: pbar.error()
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 when reducing:
from tqdm_tag import TqdmTag
pbar = TqdmTag(
range(100),
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", color="yellow", status=1)
if i % 10 == 2: pbar.tag("error", color="red", status=2)
API
| Class | Description |
|---|---|
TqdmTag |
Core class — drop-in tqdm replacement with .tag() support |
TqdmErrorTag |
Subclass pre-wired with warn / error tags and .warn() / .error() helpers |
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.3.1.tar.gz.
File metadata
- Download URL: tqdm_tag-0.3.1.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5a044f6b6aebec48e216f0097a1ca14c4d804a54b7d7782dfc633755b822cba
|
|
| MD5 |
97735fdd16962e92879edbf4df738579
|
|
| BLAKE2b-256 |
0524a5076881b1ebcef103da701fbe89a55746c569cbd7d9dd3392fc92421b65
|
Provenance
The following attestation bundles were made for tqdm_tag-0.3.1.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.3.1.tar.gz -
Subject digest:
e5a044f6b6aebec48e216f0097a1ca14c4d804a54b7d7782dfc633755b822cba - Sigstore transparency entry: 1684114766
- Sigstore integration time:
-
Permalink:
ColinMoldenhauer/tqdm-tag@38bd0e691da65d9051a0c5037535eb7fb7a967c7 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/ColinMoldenhauer
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@38bd0e691da65d9051a0c5037535eb7fb7a967c7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tqdm_tag-0.3.1-py3-none-any.whl.
File metadata
- Download URL: tqdm_tag-0.3.1-py3-none-any.whl
- Upload date:
- Size: 10.0 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 |
576533170988f4cdcc29ef184e6e81d6cce664c4f71bf3586246b3c1448869c7
|
|
| MD5 |
e164f186869b68a7a1aa1c8e4c758d0f
|
|
| BLAKE2b-256 |
bf46444f0af7f5a0b435dd515c397d19b14229ee5fc8fefb3a2f25241c80b48d
|
Provenance
The following attestation bundles were made for tqdm_tag-0.3.1-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.3.1-py3-none-any.whl -
Subject digest:
576533170988f4cdcc29ef184e6e81d6cce664c4f71bf3586246b3c1448869c7 - Sigstore transparency entry: 1684114882
- Sigstore integration time:
-
Permalink:
ColinMoldenhauer/tqdm-tag@38bd0e691da65d9051a0c5037535eb7fb7a967c7 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/ColinMoldenhauer
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@38bd0e691da65d9051a0c5037535eb7fb7a967c7 -
Trigger Event:
push
-
Statement type: