py-bar/README.md

105 lines
3.0 KiB
Markdown
Raw Normal View History

2016-05-10 21:16:56 -04:00
# progressbar
Python CLI Progress bar. This module is an iterator that can not only, iterate, but display its self as a progressbar along with some other usefull iformation such as iterations a second, estimated time, elapsed time, etc.
2016-02-09 15:22:56 -05:00
2017-01-12 10:15:59 -05:00
`00:25 100% [====================] [100/100] 3.99/s 00:00`
2016-05-11 11:38:23 -04:00
2016-02-09 15:22:28 -05:00
### Authors
2016-05-10 21:16:56 -04:00
* [Zak Timson](http://zakscode.com)
2016-02-09 15:22:56 -05:00
2016-02-09 15:22:28 -05:00
### License
2016-02-09 15:24:40 -05:00
GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007. read LICENSE for more
2016-02-09 15:22:56 -05:00
2016-02-09 15:22:28 -05:00
### Install
2016-05-10 21:16:56 -04:00
Copy the script to your project and import it with:
2016-05-11 11:38:23 -04:00
2017-01-12 10:15:59 -05:00
`import progressbar`
2016-05-11 11:38:23 -04:00
2016-05-10 21:16:56 -04:00
or
2016-05-11 11:38:23 -04:00
2017-01-12 10:15:59 -05:00
`from progressbar import Progressbar`
2016-05-10 21:16:56 -04:00
### Quick Start
Use in a forloop:
2016-05-11 11:38:23 -04:00
2017-01-12 10:15:59 -05:00
`for i in Progressbar(100)`
2016-05-10 21:16:56 -04:00
Dont like it auto writing to the stdout? Do it your self.
2016-05-11 11:38:23 -04:00
2016-05-10 21:16:56 -04:00
```
progress = Progressbar(100, display=False) # display false stops the auto writing
for i in progress:
print(str(progress)) # using the to string will maunually write it
```
2016-02-09 15:22:56 -05:00
2016-05-11 11:38:23 -04:00
Maybe you dont want to use it as an iterable and you just want a progressbar. You can manually control its progress. Example, you want to view download progress:
```
progress = Progressbar(download_size, unit=" MB/s") # create the object
...
progress.__iter__() # This will start the clock and initiate the iterable
...
progress.current = 220 # set the curent progress ex. 200/1000 Mb downloaded
download_speed = progress.rate() # get any sort of stistics you may want, the download rate for exmple
print(progress) # display progress bar. Manually iterating the object it will not display automaticly
```
2017-01-12 10:15:59 -05:00
This would print (Underscores to maintain spacing):
2016-05-11 11:38:23 -04:00
2017-01-12 10:15:59 -05:00
`00:53 20% [====________________] [ 200/1000] 3.75 Mb/s 03:32`
2016-05-11 11:38:23 -04:00
2016-02-09 15:22:28 -05:00
### API
2016-05-11 11:38:23 -04:00
**Class: Progressbar**
2016-05-10 21:16:56 -04:00
2016-05-10 21:22:12 -04:00
**Attributes**
2016-05-10 21:16:56 -04:00
start - iterator starting position
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
end - iterator ending position
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
current - curent iteration
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
step - number to be added to current each iteraton
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
length - length of characters in the progress bar
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
units - unit to append to rate
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
color - ANSI escape code to change color of text
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
display - automaticly display the to string with each iteration
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
bar_format - string which dictates how things are displayed ex "{elapesed} - {eta}" could look like: 00:00 - 00:10. See the statistics portion to see what can be displayed
2016-05-10 21:22:12 -04:00
**Available Statistics**
2016-05-10 21:16:56 -04:00
elapsed - running time of iterator. displayed as: mm:ss
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
percentage - percentage of completion. displayed as: 100%
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
bar - the progress bar. displayed as: |==========|
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
fraction - current / end. displayed as: [100/100]
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
rate - iterations per second. displayed as: 2.00/s (unit can be changed, see units attribute)
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
eat - estimated time until completion. displayed as: mm:ss
2016-05-10 21:22:12 -04:00
**Methods**
2016-05-10 21:16:56 -04:00
elapsed(self) - running time of iterator
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
estimated_time(self) - estimated time until iterator completes
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
fraction(self) - create string representing the fraction, complete over total
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
generate_bar - generates the progress bar and returns string
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
per_second - calculates the rate or speed of iterations per second
2016-05-10 21:22:12 -04:00
2016-05-10 21:16:56 -04:00
percentage - floating point of completion
2016-02-09 15:22:56 -05:00
2016-02-09 15:22:28 -05:00
### Bug Reporting
2016-05-10 21:22:12 -04:00
Please submit bugs to the github [issue tracker](https://github.com/zaktimson/progressbar/issues)