Skip to main content

Colored one-line progress bar with stdout interception

Project description

line-progressor

Color progress bar for terminal loops.
Single-file module. Handles noisy iterables that print. Dynamic width. ETA. Green done, red remaining.


Install

pip install line-progressor
# dependency: colorama

Quick start

from time import sleep
from line_progressor import wrap

for _ in wrap(range(100)):  # intercepts stdout by default
    sleep(0.02)

Example output:

[══════════════════──────────────]  50% Processing... ETA 00:01

Noisy iterables that print

from line_progressor import wrap
import time

class Talker:
    def __init__(self, n): self.n = n
    def __len__(self): return self.n
    def __iter__(self):
        for i in range(self.n):
            print(f"line {i}")   # stdout noise
            yield i

for _ in wrap(Talker(20)):
    time.sleep(0.05)

wrap captures stdout, writes user lines above a stable one-line bar, then re-renders the bar.


Choose output stream

  • Keep your print() on stdout, bar on stderr (default):
for _ in wrap(range(100), stream=sys.stderr):
    ...
  • Put bar on stdout:
for _ in wrap(range(100), stream=sys.stdout):
    ...

Customize text and style

for _ in wrap(
    range(100),
    running_text="Crunching...",
    done_text="All finished!",
    fill_char="═",
    empty_char="─",
    width=50,
):
    ...
  • Bar: green filled, red remaining
  • Percent: red while running, green when done
  • Status: gray while running, green when done

Disable interception

for _ in wrap(range(100), intercept_stdout=False):
    ...

Manual control

from line_progressor import ProgressBar
pb = ProgressBar(total=5)

with pb.patch_stdout():
    for i in range(5):
        print("log line")
        pb.update(1)

pb.finish()

API

wrap(iterable, total=None, *, intercept_stdout=True, enabled=None, stream=sys.stderr, **kwargs) -> iterator

  • Wraps any iterable and renders progress.
  • total inferred via len(iterable) if omitted.
  • intercept_stdout=True captures print() and keeps the bar stable.
  • enabled defaults to stream.isatty(). When intercept_stdout=True and enabled is None, it is forced to True.
  • stream is where the bar renders.
  • **kwargs are forwarded to ProgressBar(...).

ProgressBar(total, *, width=40, stream=sys.stderr, enabled=None, fmt="[{bar}] {pct} {status}{eta}", fill_char="═", empty_char="─", time_fn=time.time, running_text="Processing...", done_text="Done!")

  • Methods: update(n=1), finish(), patch_stdout()

Behavior notes

  • Dynamic width: bar shrinks to avoid wrapping; ETA is dropped first if the line would wrap.
  • TTY detection: set enabled=True to force rendering when piping or in non-TTY environments.
  • Windows: requires colorama (this module calls colorama.init()).
  • Performance: renders are throttled to ~60 FPS.

Troubleshooting

  • Bar not visible: pass enabled=True or choose a visible stream.
  • Bar moves down on prints: use default interception or with pb.patch_stdout():.
  • Jupyter/IDE consoles: ANSI behavior varies. Prefer a real terminal.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

line_progressor-0.1.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

line_progressor-0.1.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file line_progressor-0.1.2.tar.gz.

File metadata

  • Download URL: line_progressor-0.1.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for line_progressor-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c781efeffca78f06886e8d2220bbb04f1d36bdb8416091a66aa120b585ba641a
MD5 c88cd728c70a1ec3af36a9b2d6e3dcbc
BLAKE2b-256 199cf46a646b4b0ca188ae5fb614f32b171d534f6d7b82c8c5400501cb39cdff

See more details on using hashes here.

File details

Details for the file line_progressor-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for line_progressor-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 aaeb082e43ba96638087864968351357df1a963caaba14ba1e0be40fcb1d0c89
MD5 cfca66fec6b3bbff96fafd14b435cd3e
BLAKE2b-256 cdd896d4bb2abcead7785718292adccb887e715929fa298ed51341ba31d48c9e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page