There are 7 progress bars to choose from:
BarChargingBarFillingSquaresBarFillingCirclesBarIncrementalBarPixelBarShadyBar
To use them, just call next to advance and finish to finish:
fromprogress.barimportBarbar=Bar('Processing', max=20)
foriinrange(20):
# Do some workbar.next()
bar.finish()or use any bar of this class as a context manager:
fromprogress.barimportBarwithBar('Processing', max=20) asbar:
foriinrange(20):
# Do some workbar.next()The result will be a bar like the following:
Processing |############# | 42/100
To simplify the common case where the work is done in an iterator, you can
use the iter method:
foriinBar('Processing').iter(it):
# Do some workProgress bars are very customizable, you can change their width, their fill character, their suffix and more:
bar=Bar('Loading', fill='@', suffix='%(percent)d%%')This will produce a bar like the following:
Loading |@@@@@@@@@@@@@ | 42%
You can use a number of template arguments in message and suffix:
| Name | Value |
|---|---|
| index | current value |
| max | maximum value |
| remaining | max - index |
| progress | index / max |
| percent | progress * 100 |
| avg | simple moving average time per item (in seconds) |
| elapsed | elapsed time in seconds |
| elapsed_td | elapsed as a timedelta (useful for printing as a string) |
| eta | avg * remaining |
| eta_td | eta as a timedelta (useful for printing as a string) |
Instead of passing all configuration options on instantiation, you can create your custom subclass:
classFancyBar(Bar):
message='Loading'fill='*'suffix='%(percent).1f%% - %(eta)ds'You can also override any of the arguments or create your own:
classSlowBar(Bar):
suffix='%(remaining_hours)d hours remaining'@propertydefremaining_hours(self):
returnself.eta//3600For actions with an unknown number of steps you can use a spinner:
fromprogress.spinnerimportSpinnerspinner=Spinner('Loading ')
whilestate!='FINISHED':
# Do some workspinner.next()There are 5 predefined spinners:
SpinnerPieSpinnerMoonSpinnerLineSpinnerPixelSpinner
Download from PyPi
pip install progressThere are a number of other classes available too, please check the source or subclass one of them to create your own.
progress is licensed under ISC
