Skip to content
An utility module to represent progress in the form of a progress bar.
Python
Branch: master
Clone or download
anler Merge pull request #8 from ralfharing/master
remove stored step to increase accuracy
Latest commit cf35b6e Apr 15, 2014
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
AUTHORS Adding AUTHORS file Feb 9, 2014
LICENSE
README.markdown fix readme example Apr 15, 2014
demo.py
progressbar.py allow decrementing the progress bar Apr 15, 2014
setup.py
tests.py Updated README Jul 13, 2011

README.markdown

Python Progressbar

A progressbar utility for command line programs. Progressbar is a Python module which contains two class so far:

  1. ProgressBar
  2. AnimatedProgressBar

ProgressBar class implements all the base stuff that makes progress bars work as they do and allows some basic customization. AnimatedProgressBar class extends ProgressBar to allow you to use it straightforward in your scripts. By default the AnimatedProgressBar sends the output to sys.stdout but you can change this passing the stdout keyword parameter which must be a file-like object.

Usage

Here is some basic usage with the default options:

>>> from progressbar import ProgressBar
>>> p = ProgressBar()
>>> print p
[>............] 0%
>>> p + 1
>>> print p
[=>...........] 10%
>>> p + 9
>>> print p
[============>] 0%

And here another example with different options:

>>> from progressbar import ProgressBar
>>> custom_options = {
...     'end': 100,
...     'width': 20,
...     'fill': '#',
...     'format': '%(progress)s%% [%(fill)s%(blank)s]'
... }
>>> p = ProgressBar(**custom_options)
>>> print p
0% [....................]
>>> p + 5
>>> print p
5% [#...................]
>>> p + 95
>>> print p
100% [####################]

Finally, a real example where I had to use it:

>>> import ftplib
>>> import progressbar
>>>
>>> ftp = ftplib.FTP('ftp.myserver.com', 'user', 'passwd')
>>> filesize = ftp.size('path/to/remotefile.zip')
>>> progress = progressbar.AnimatedProgressBar(end=filesize, width=50)
>>>
>>> with open('localfile.zip', 'w') as f:
>>>     def callback(chunk):
>>>         f.write(chunk)
>>>         progress + len(chunk)
>>>
>>>         # Visual feedback of the progress!
>>>         progress.show_progress()
>>>
>>>     ftp.retrbinary('RETR path/to/remotefile.zip', callback)

Contribution

If you find it useful, fork the repository, improve it and request a pull.

You can’t perform that action at this time.