progressbar.bar module

class progressbar.bar.DataTransferBar(min_value=0, max_value=None, widgets=None, left_justify=True, initial_value=0, poll_interval=None, widget_kwargs=None, custom_len=<built-in function len>, **kwargs)[source]

Bases: progressbar.bar.ProgressBar

A progress bar with sensible defaults for downloads etc.

This assumes that the values its given are numbers of bytes.

default_widgets()[source]
class progressbar.bar.DefaultFdMixin(fd=<open file '<stderr>', mode 'w'>, **kwargs)[source]

Bases: progressbar.bar.ProgressBarMixinBase

finish(*args, **kwargs)[source]
update(*args, **kwargs)[source]
class progressbar.bar.NullBar(min_value=0, max_value=None, widgets=None, left_justify=True, initial_value=0, poll_interval=None, widget_kwargs=None, custom_len=<built-in function len>, **kwargs)[source]

Bases: progressbar.bar.ProgressBar

Progress bar that does absolutely nothing. Useful for single verbosity flags

finish(*args, **kwargs)[source]
start(*args, **kwargs)[source]
update(*args, **kwargs)[source]
class progressbar.bar.ProgressBar(min_value=0, max_value=None, widgets=None, left_justify=True, initial_value=0, poll_interval=None, widget_kwargs=None, custom_len=<built-in function len>, **kwargs)[source]

Bases: progressbar.bar.StdRedirectMixin, progressbar.bar.ResizableMixin, progressbar.bar.ProgressBarBase

The ProgressBar class which updates and prints the bar.

Parameters:
  • min_value (int) – The minimum/start value for the progress bar
  • max_value (int) – The maximum/end value for the progress bar. Defaults to _DEFAULT_MAXVAL
  • widgets (list) – The widgets to render, defaults to the result of default_widget()
  • left_justify (bool) – Justify to the left if True or the right if False
  • initial_value (int) – The value to start with
  • poll_interval (float) – The update interval in time. Note that this is always limited by _MINIMUM_UPDATE_INTERVAL
  • widget_kwargs (dict) – The default keyword arguments for widgets
  • custom_len (function) – Method to override how the line width is calculated. When using non-latin characters the width calculation might be off by default

A common way of using it is like:

>>> progress = ProgressBar().start()
>>> for i in range(100):
...     progress.update(i+1)
...     # do something
...
>>> progress.finish()

You can also use a ProgressBar as an iterator:

>>> progress = ProgressBar()
>>> some_iterable = range(100)
>>> for i in progress(some_iterable):
...     # do something
...     pass
...

Since the progress bar is incredibly customizable you can specify different widgets of any type in any order. You can even write your own widgets! However, since there are already a good number of widgets you should probably play around with them before moving on to create your own widgets.

The term_width parameter represents the current terminal width. If the parameter is set to an integer then the progress bar will use that, otherwise it will attempt to determine the terminal width falling back to 80 columns if the width cannot be determined.

When implementing a widget’s update method you are passed a reference to the current progress bar. As a result, you have access to the ProgressBar’s methods and attributes. Although there is nothing preventing you from changing the ProgressBar you should treat it as read only.

Useful methods and attributes include (Public API):
  • value: current progress (min_value <= value <= max_value)
  • max_value: maximum (and final) value
  • end_time: not None if the bar has finished (reached 100%)
  • start_time: the time when start() method of ProgressBar was called
  • seconds_elapsed: seconds elapsed since start_time and last call to
    update
data()[source]
Returns:
  • max_value: The maximum value (can be None with iterators)
  • start_time: Start time of the widget
  • last_update_time: Last update time of the widget
  • end_time: End time of the widget
  • value: The current value
  • previous_value: The previous value
  • updates: The total update count
  • total_seconds_elapsed: The seconds since the bar started
  • seconds_elapsed: The seconds since the bar started modulo 60
  • minutes_elapsed: The minutes since the bar started modulo 60
  • hours_elapsed: The hours since the bar started modulo 24
  • days_elapsed: The hours since the bar started
  • time_elapsed: The raw elapsed datetime.timedelta object
  • percentage: Percentage as a float or None if no max_value is available
  • dynamic_messages: Dictionary of user-defined DynamicMessage‘s
Return type:dict
default_widgets()[source]
finish(end=u'\n')[source]

Puts the ProgressBar bar in the finished state.

Also flushes and disables output buffering if this was the last progressbar running.

Parameters:end (str) – The string to end the progressbar with, defaults to a newline
get_last_update_time()[source]
init()[source]

(re)initialize values to original state so the progressbar can be used (again)

last_update_time
next()
percentage

Return current percentage, returns None if no max_value is given

>>> progress = ProgressBar()
>>> progress.max_value = 10
>>> progress.min_value = 0
>>> progress.value = 0
>>> progress.percentage
0.0
>>>
>>> progress.value = 1
>>> progress.percentage
10.0
>>> progress.value = 10
>>> progress.percentage
100.0
>>> progress.min_value = -10
>>> progress.percentage
100.0
>>> progress.value = 0
>>> progress.percentage
50.0
>>> progress.value = 5
>>> progress.percentage
75.0
>>> progress.value = -5
>>> progress.percentage
25.0
>>> progress.max_value = None
>>> progress.percentage
set_last_update_time(value)[source]
start(max_value=None, init=True)[source]

Starts measuring time, and prints the bar at 0%.

It returns self so you can use it like this:

Parameters:
  • max_value (int) – The maximum value of the progressbar
  • reinit (bool) – Initialize the progressbar, this is useful if you wish to reuse the same progressbar but can be disabled if data needs to be passed along to the next run
>>> pbar = ProgressBar().start()
>>> for i in range(100):
...    # do something
...    pbar.update(i+1)
...
>>> pbar.finish()
update(value=None, force=False, **kwargs)[source]

Updates the ProgressBar to a new value.

class progressbar.bar.ProgressBarBase(**kwargs)[source]

Bases: _abcoll.Iterable, progressbar.bar.ProgressBarMixinBase

class progressbar.bar.ProgressBarMixinBase(**kwargs)[source]

Bases: object

finish()[source]
start(**kwargs)[source]
update(value=None)[source]
class progressbar.bar.ResizableMixin(term_width=None, **kwargs)[source]

Bases: progressbar.bar.ProgressBarMixinBase

finish()[source]
class progressbar.bar.StdRedirectMixin(redirect_stderr=False, redirect_stdout=False, **kwargs)[source]

Bases: progressbar.bar.DefaultFdMixin

finish(end=u'\n')[source]
start(*args, **kwargs)[source]
update(value=None)[source]