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>, max_error=True, **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.
-
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>, max_error=True, **kwargs)[source]¶ Bases:
progressbar.bar.ProgressBar
Progress bar that does absolutely nothing. Useful for single verbosity flags
-
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>, max_error=True, **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
- max_error (bool) – When True the progressbar will raise an error if it goes beyond it’s set max_value. Otherwise the max_value is simply raised when needed
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
-
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
-
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
-
class
progressbar.bar.
ProgressBarBase
(**kwargs)[source]¶ Bases:
_abcoll.Iterable
,progressbar.bar.ProgressBarMixinBase