progressbar

Platforms: Unix, Linux

Module information :

Text progressbar library for python.

This library provides a text mode progressbar. This is tipically used to display the progress of a long running operation, providing a visual clue that processing is underway.

The ProgressBar class manages the progress, and the format of the line is given by a number of widgets. A widget is an object that may display differently depending on the state of the progress.

There are three types of widget:

  • a string, which always shows itself;
  • a ProgressBarWidget, which may return a different value every time its update method is called; and
  • a ProgressBarWidgetHFill, which is like ProgressBarWidget, except it expands to fill the remaining width of the line.

The progressbar module is very easy to use, yet very powerful. And automatically supports features like auto-resizing when available.

class progressbar.Bar(marker='#', left='|', right='|')[source]

The bar of progress. It will strech to fill the line.

class progressbar.ETA[source]

Widget for the Estimated Time of Arrival

class progressbar.FileTransferSpeed[source]

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

class progressbar.Percentage[source]

Just the percentage done.

class progressbar.ProgressBar(maxval=100, widgets=[, <progressbar.Percentage object at 0x10d5f50>, ' ', <progressbar.Bar object at 0x10d5f10>], term_width=None, fd=<open file '<stderr>', mode 'w' at 0x2ba0095d5140>)[source]

This is the ProgressBar class, it updates and prints the bar.

The term_width parameter may be an integer. Or None, in which case it will try to guess it, if it fails it will default to 80 columns.

The simple use is like this:

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

But anything you want to do is possible (well, almost anything). You can supply different widgets of any type in any order. And you can even write your own widgets! There are many widgets already shipped and you should experiment with them.

When implementing a widget update method you may access any attribute or function of the ProgressBar object calling the widget’s update method. The most important attributes you would like to access are: - currval current value of the progress, 0 <= currval <= maxval - maxval maximum (and final) value of the progress - finished True if the bar is have finished (reached 100%), False o/w - start_time first time update() method of ProgressBar was called - seconds_elapsed seconds elapsed since start_time - percentage() percentage of the progress (this is a method)

finish()[source]

Used to tell the progress is finished.

percentage()[source]

Returns the percentage of the progress.

start()[source]

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

It returns self so you can use it like this:

>>> pbar = ProgressBar().start()
>>> for i in xrange(100):
...    # do something
...    pbar.update(i+1)
...
>>> pbar.finish()
update(value)[source]

Updates the progress bar to a new value.

class progressbar.ProgressBarWidget[source]

This is an element of ProgressBar formatting.

The ProgressBar object will call it’s update value when an update is needed. It’s size may change between call, but the results will not be good if the size changes drastically and repeatedly.

update(pbar)[source]

Returns the string representing the widget.

The parameter pbar is a reference to the calling ProgressBar, where one can access attributes of the class for knowing how the update must be made.

At least this function must be overriden.

class progressbar.ProgressBarWidgetHFill[source]

This is a variable width element of ProgressBar formatting.

The ProgressBar object will call it’s update value, informing the width this object must the made. This is like TeX hfill, 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.

update(pbar, width)[source]

Returns the string representing the widget.

The parameter pbar is a reference to the calling ProgressBar, where one can access attributes of the class for knowing how the update must be made. The parameter width is the total horizontal width the widget must have.

At least this function must be overriden.

class progressbar.ReverseBar(marker='#', left='|', right='|')[source]

The reverse bar of progress, or bar of regress. :)

class progressbar.RotatingMarker(markers='|/-\')[source]

A rotating marker for filling the bar of progress.

Previous topic

modules

This Page