Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
progressbar2 documentation
progressbar2 documentation

Documentation

  • Installation
  • Tutorial
    • Step 1: Wrap a loop with progressbar
    • Step 2: Update a ProgressBar explicitly
    • Step 3: Give the bar a max_value
    • Step 4: Choose your own widgets
    • Step 5: Print safely with redirect_stdout
  • How-to guides
    • Wrap an iterable without managing the bar yourself
    • Print while a bar is running
    • Send logging output above a running bar
    • Print one line per update instead of overwriting
    • Color a bar, solid or gradient
    • Write a custom widget
    • Show a custom value next to the bar
    • Put live values in the prefix or suffix
    • Switch from tqdm without renaming your keywords
    • Report a transfer’s size and speed
    • Show progress when the total isn’t known
    • Track several jobs at once with MultiBar
    • Stack independent bars without MultiBar
    • Run a batch in parallel with progress
  • Widget reference
    • AbsoluteETA
    • AdaptiveETA
    • AdaptiveTransferSpeed
    • AnimatedMarker
    • Bar
    • BouncingBar
    • Counter
    • CurrentTime
    • DataSize
    • DynamicMessage
    • ETA
    • FileTransferSpeed
    • FormatCustomText
    • FormatLabel
    • FormatLabelBar
    • GranularBar
    • JobStatusBar
    • MultiProgressBar
    • MultiRangeBar
    • Percentage
    • PercentageLabelBar
    • Postfix
    • ReverseBar
    • RotatingMarker
    • SimpleProgress
    • SmoothingETA
    • Timer
    • UnitProgress
    • Variable
  • Reference
    • ProgressBar
    • MultiBar
    • Parallel execution
    • progressbar CLI
    • Full module autodoc
      • progressbar.terminal package
        • progressbar.terminal.base module
        • progressbar.terminal.colors module
        • progressbar.terminal.stream module
      • progressbar.algorithms module
      • progressbar.bar module
      • progressbar.base module
      • progressbar.env module
      • progressbar.fast module
      • progressbar.multi module
      • progressbar.shortcuts module
      • progressbar.utils module
      • progressbar.widgets module
  • Explanation
    • Rendering and the update gate
    • Terminal detection
    • Performance and the fast path
    • Backwards compatibility

Project

  • Contributing
  • History
  • Support this project
Back to top
View this page
Edit this page

Print one line per update instead of overwriting¶

ProgressBar normally repaints one line in place, overwriting the previous redraw – the right behavior for an interactive terminal, but the wrong one once output is piped to a file, tee, or a log collector, where overwriting means every redraw but the last is lost.

Keeping each update in a log
"""What the bar looks like once it detects stdout isn't a terminal.

`ProgressBar` normally checks whether its output stream is a terminal and,
if not, switches from overwriting one line to printing a new line per
update -- the shape you want once output is piped to a file, `tee`, or a
log collector, so each redraw survives instead of being lost to the next
carriage return. That auto-detection can't be demonstrated here, since this
demo is captured through something that always presents itself as a
terminal; `line_breaks=True` forces the same rendering explicitly, and is
also the parameter to reach for if you want that behaviour even when
stdout genuinely is a terminal -- a build log, say, where every line should
stay on screen.
"""

import time

import progressbar

STEPS = 12


def main() -> None:
    with progressbar.ProgressBar(max_value=STEPS, line_breaks=True) as bar:
        for step in range(STEPS):
            bar.update(step + 1)
            time.sleep(0.05)


if __name__ == '__main__':
    main()

Pass line_breaks=True to print a full new line per update instead of overwriting. Left to auto-detect (the default, line_breaks=None), the bar checks whether its output stream is a terminal and switches to one line per update on its own once it isn’t. The demo above passes the explicit override because it records inside a terminal. The explicit line_breaks=True is also worth passing when stdout genuinely is a terminal but every line should stay on screen, such as a build log.

Next
Color a bar, solid or gradient
Previous
Send logging output above a running bar
Copyright © 2026, Rick van Hattem (Wolph)
Made with Sphinx and @pradyunsg's Furo