progressbar.widgets module

class progressbar.widgets.AbsoluteETA(format_not_started='Estimated finish time: ----/--/-- --:--:--', format_finished='Finished at: %(elapsed)s', format='Estimated finish time: %(eta)s', **kwargs)[source]

Bases: progressbar.widgets.ETA

Widget which attempts to estimate the absolute time of arrival.

class progressbar.widgets.AdaptiveETA(**kwargs)[source]

Bases: progressbar.widgets.ETA, progressbar.widgets.SamplesMixin

WidgetBase which attempts to estimate the time of arrival.

Uses a sampled average of the speed based on the 10 last updates. Very convenient for resuming the progress halfway.

class progressbar.widgets.AdaptiveTransferSpeed(**kwargs)[source]

Bases: progressbar.widgets.FileTransferSpeed, progressbar.widgets.SamplesMixin

Widget for showing the transfer speed based on the last X samples

class progressbar.widgets.AnimatedMarker(markers='|/-\', default=None, fill='', marker_wrap=None, fill_wrap=None, **kwargs)[source]

Bases: progressbar.widgets.TimeSensitiveWidgetBase

An animated marker for the progress bar which defaults to appear as if it were rotating.

class progressbar.widgets.AutoWidthWidgetBase(min_width=None, max_width=None, **kwargs)[source]

Bases: progressbar.widgets.WidgetBase

The base class for all variable width widgets.

This widget is much like the hfill command in TeX, it will expand to fill the line. You can use more than one in the same line, and they will all have the same width, and together will fill the line.

class progressbar.widgets.Bar(marker='#', left='|', right='|', fill=' ', fill_left=True, marker_wrap=None, **kwargs)[source]

Bases: progressbar.widgets.AutoWidthWidgetBase

A progress bar which stretches to fill the line.

class progressbar.widgets.BouncingBar(marker='#', left='|', right='|', fill=' ', fill_left=True, marker_wrap=None, **kwargs)[source]

Bases: progressbar.widgets.Bar, progressbar.widgets.TimeSensitiveWidgetBase

A bar which has a marker which bounces from side to side.

INTERVAL = datetime.timedelta(microseconds=100000)
class progressbar.widgets.Counter(format='%(value)d', **kwargs)[source]

Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.WidgetBase

Displays the current count

class progressbar.widgets.CurrentTime(format='Current Time: %(current_time)s', microseconds=False, **kwargs)[source]

Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.TimeSensitiveWidgetBase

Widget which displays the current (date)time with seconds resolution.

INTERVAL = datetime.timedelta(seconds=1)
current_datetime()[source]
current_time()[source]
class progressbar.widgets.DataSize(variable='value', format='%(scaled)5.1f %(prefix)s%(unit)s', unit='B', prefixes=('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'), **kwargs)[source]

Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.WidgetBase

Widget for showing an amount of data transferred/processed.

Automatically formats the value (assumed to be a count of bytes) with an appropriate sized unit, based on the IEC binary prefixes (powers of 1024).

class progressbar.widgets.DynamicMessage(name, format='{name}: {formatted_value}', width=6, precision=3, **kwargs)[source]

Bases: progressbar.widgets.Variable

Kept for backwards compatibility, please use Variable instead.

class progressbar.widgets.ETA(format_not_started='ETA: --:--:--', format_finished='Time: %(elapsed)8s', format='ETA: %(eta)8s', format_zero='ETA: 00:00:00', format_NA='ETA: N/A', **kwargs)[source]

Bases: progressbar.widgets.Timer

WidgetBase which attempts to estimate the time of arrival.

class progressbar.widgets.FileTransferSpeed(format='%(scaled)5.1f %(prefix)s%(unit)-s/s', inverse_format='%(scaled)5.1f s/%(prefix)s%(unit)-s', unit='B', prefixes=('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'), **kwargs)[source]

Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.TimeSensitiveWidgetBase

Widget for showing the current transfer speed (useful for file transfers).

class progressbar.widgets.FormatCustomText(format: str, mapping: Optional[Dict[str, Any]] = None, **kwargs)[source]

Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.WidgetBase

copy = False
mapping = {}
update_mapping(**mapping)[source]
class progressbar.widgets.FormatLabel(format: str, **kwargs)[source]

Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.WidgetBase

Displays a formatted label

>>> label = FormatLabel('%(value)s', min_width=5, max_width=10)
>>> class Progress:
...     pass
>>> label = FormatLabel('{value} :: {value:^6}', new_style=True)
>>> str(label(Progress, dict(value='test')))
'test ::  test '
mapping = {'elapsed': ('total_seconds_elapsed', <function format_time>), 'finished': ('end_time', None), 'last_update': ('last_update_time', None), 'max': ('max_value', None), 'seconds': ('seconds_elapsed', None), 'start': ('start_time', None), 'value': ('value', None)}
class progressbar.widgets.FormatLabelBar(format, **kwargs)[source]

Bases: progressbar.widgets.FormatLabel, progressbar.widgets.Bar

A bar which has a formatted label in the center.

class progressbar.widgets.FormatWidgetMixin(format: str, new_style: bool = False, **kwargs)[source]

Bases: abc.ABC

Mixin to format widgets using a formatstring

Variables available:
  • max_value: The maximum value (can be None with iterators)
  • value: The current value
  • 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: Shortcut for HH:MM:SS time since the bar started including days
  • percentage: Percentage as a float
get_format(progress: ProgressBarMixinBase, data: Data, format: types.Optional[str] = None) → str[source]
class progressbar.widgets.GranularBar(markers=' ▏▎▍▌▋▊▉█', left='|', right='|', **kwargs)[source]

Bases: progressbar.widgets.AutoWidthWidgetBase

A progressbar that can display progress at a sub-character granularity by using multiple marker characters.

Examples of markers:
  • Smooth: ` ▏▎▍▌▋▊▉█` (default)
  • Bar: ` ▁▂▃▄▅▆▇█`
  • Snake: ` ▖▌▛█`
  • Fade in: ` ░▒▓█`
  • Dots: ` ⡀⡄⡆⡇⣇⣧⣷⣿`
  • Growing circles: ` .oO`

The markers can be accessed through GranularMarkers. GranularMarkers.dots for example

class progressbar.widgets.GranularMarkers[source]

Bases: object

bar = ' ▁▂▃▄▅▆▇█'
dots = ' ⡀⡄⡆⡇⣇⣧⣷⣿'
fade_in = ' ░▒▓█'
growing_circles = ' .oO'
smooth = ' ▏▎▍▌▋▊▉█'
snake = ' ▖▌▛█'
class progressbar.widgets.MultiProgressBar(name, markers=' ▁▂▃▄▅▆▇█', **kwargs)[source]

Bases: progressbar.widgets.MultiRangeBar

get_values(progress: ProgressBarMixinBase, data: Data)[source]
class progressbar.widgets.MultiRangeBar(name, markers, **kwargs)[source]

Bases: progressbar.widgets.Bar, progressbar.widgets.VariableMixin

A bar with multiple sub-ranges, each represented by a different symbol

The various ranges are represented on a user-defined variable, formatted as

[
    ['Symbol1', amount1],
    ['Symbol2', amount2],
    ...
]
get_values(progress: ProgressBarMixinBase, data: Data)[source]
class progressbar.widgets.Percentage(format='%(percentage)3d%%', na='N/A%%', **kwargs)[source]

Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.WidgetBase

Displays the current percentage as a number with a percent sign.

get_format(progress: ProgressBarMixinBase, data: Data, format=None)[source]
class progressbar.widgets.PercentageLabelBar(format='%(percentage)2d%%', na='N/A%%', **kwargs)[source]

Bases: progressbar.widgets.Percentage, progressbar.widgets.FormatLabelBar

A bar which displays the current percentage in the center.

class progressbar.widgets.ReverseBar(marker='#', left='|', right='|', fill=' ', fill_left=False, **kwargs)[source]

Bases: progressbar.widgets.Bar

A bar which has a marker that goes from right to left

progressbar.widgets.RotatingMarker

alias of progressbar.widgets.AnimatedMarker

class progressbar.widgets.SamplesMixin(samples=datetime.timedelta(seconds=2), key_prefix=None, **kwargs)[source]

Bases: progressbar.widgets.TimeSensitiveWidgetBase

Mixing for widgets that average multiple measurements

Note that samples can be either an integer or a timedelta to indicate a certain amount of time

>>> class progress:
...     last_update_time = datetime.datetime.now()
...     value = 1
...     extra = dict()
>>> samples = SamplesMixin(samples=2)
>>> samples(progress, None, True)
(None, None)
>>> progress.last_update_time += datetime.timedelta(seconds=1)
>>> samples(progress, None, True) == (datetime.timedelta(seconds=1), 0)
True
>>> progress.last_update_time += datetime.timedelta(seconds=1)
>>> samples(progress, None, True) == (datetime.timedelta(seconds=1), 0)
True
>>> samples = SamplesMixin(samples=datetime.timedelta(seconds=1))
>>> _, value = samples(progress, None)
>>> value
[1, 1]
>>> samples(progress, None, True) == (datetime.timedelta(seconds=1), 0)
True
get_sample_times(progress: ProgressBarMixinBase, data: Data)[source]
get_sample_values(progress: ProgressBarMixinBase, data: Data)[source]
class progressbar.widgets.SimpleProgress(format='%(value_s)s of %(max_value_s)s', **kwargs)[source]

Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.WidgetBase

Returns progress as a count of the total (e.g.: “5 of 47”)

DEFAULT_FORMAT = '%(value_s)s of %(max_value_s)s'
class progressbar.widgets.TimeSensitiveWidgetBase(min_width=None, max_width=None, **kwargs)[source]

Bases: progressbar.widgets.WidgetBase

The base class for all time sensitive widgets.

Some widgets like timers would become out of date unless updated at least every INTERVAL

INTERVAL = datetime.timedelta(microseconds=100000)
class progressbar.widgets.Timer(format='Elapsed Time: %(elapsed)s', **kwargs)[source]

Bases: progressbar.widgets.FormatLabel, progressbar.widgets.TimeSensitiveWidgetBase

WidgetBase which displays the elapsed seconds.

static format_time(timestamp: Union[datetime.timedelta, datetime.date, datetime.datetime, str, int, float, None], precision: datetime.timedelta = datetime.timedelta(seconds=1)) → str

Formats timedelta/datetime/seconds

>>> format_time('1')
'0:00:01'
>>> format_time(1.234)
'0:00:01'
>>> format_time(1)
'0:00:01'
>>> format_time(datetime.datetime(2000, 1, 2, 3, 4, 5, 6))
'2000-01-02 03:04:05'
>>> format_time(datetime.date(2000, 1, 2))
'2000-01-02'
>>> format_time(datetime.timedelta(seconds=3661))
'1:01:01'
>>> format_time(None)
'--:--:--'
>>> format_time(format_time)  # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
TypeError: Unknown type ...
class progressbar.widgets.Variable(name, format='{name}: {formatted_value}', width=6, precision=3, **kwargs)[source]

Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.VariableMixin, progressbar.widgets.WidgetBase

Displays a custom variable.

class progressbar.widgets.VariableMixin(name, **kwargs)[source]

Bases: object

Mixin to display a custom user variable

class progressbar.widgets.WidgetBase(min_width=None, max_width=None, **kwargs)[source]

Bases: progressbar.widgets.WidthWidgetMixin

The base class for all widgets

The ProgressBar will call the widget’s update value when the widget should be updated. The widget’s size may change between calls, but the widget may display incorrectly if the size changes drastically and repeatedly.

The INTERVAL timedelta informs the ProgressBar that it should be updated more often because it is time sensitive.

The widgets are only visible if the screen is within a specified size range so the progressbar fits on both large and small screens.

WARNING: Widgets can be shared between multiple progressbars so any state information specific to a progressbar should be stored within the progressbar instead of the widget.

Variables available:
  • min_width: Only display the widget if at least min_width is left
  • max_width: Only display the widget if at most max_width is left
  • weight: Widgets with a higher weigth will be calculated before widgets with a lower one
  • copy: Copy this widget when initializing the progress bar so the progressbar can be reused. Some widgets such as the FormatCustomText require the shared state so this needs to be optional
copy = True
class progressbar.widgets.WidthWidgetMixin(min_width=None, max_width=None, **kwargs)[source]

Bases: abc.ABC

Mixing to make sure widgets are only visible if the screen is within a specified size range so the progressbar fits on both large and small screens.

Variables available:
  • min_width: Only display the widget if at least min_width is left
  • max_width: Only display the widget if at most max_width is left
>>> class Progress:
...     term_width = 0
>>> WidthWidgetMixin(5, 10).check_size(Progress)
False
>>> Progress.term_width = 5
>>> WidthWidgetMixin(5, 10).check_size(Progress)
True
>>> Progress.term_width = 10
>>> WidthWidgetMixin(5, 10).check_size(Progress)
True
>>> Progress.term_width = 11
>>> WidthWidgetMixin(5, 10).check_size(Progress)
False
check_size(progress: ProgressBarMixinBase)[source]
progressbar.widgets.create_marker(marker, wrap=None)[source]
progressbar.widgets.create_wrapper(wrapper)[source]

Convert a wrapper tuple or format string to a format string

>>> create_wrapper('')
>>> print(create_wrapper('a{}b'))
a{}b
>>> print(create_wrapper(('a', 'b')))
a{}b
progressbar.widgets.string_or_lambda(input_)[source]
progressbar.widgets.wrapper(function, wrapper_)[source]

Wrap the output of a function in a template string or a tuple with begin/end strings