Sebastian Raschka
last updated: 10/10/2014

PyPrind 2.6.2 demo


I would be happy to hear your comments and suggestions.
Please feel free to drop me a note via twitter, email, or google+.


Sections




In [ ]:
import pyprind



Basic Progress Bar


In [ ]:
n = 150000

bar = pyprind.ProgBar(n)
for i in range(n):
    # do some computation
    bar.update()



Basic Percentage Indicator

Note: the Percentage indicator is significantly slower due to background computation.
Thus, it is recommended for tasks with less iterations but longer computational time per iteration.


In [ ]:
n = 1500

perc = pyprind.ProgPercent(n)
for i in range(n):
    # do some computation
    perc.update()



Progress Bar/Percentage Indicator - Reporting tracking information

Simply print() the tracking object after the tracking has completed.


In [ ]:
n = 150000

bar = pyprind.ProgBar(n)
for i in range(n):
    # do some computation
    bar.update()
print(bar)

In [ ]:
n = 150000

bar = pyprind.ProgBar(n, monitor=True, title='Job_1')
for i in range(n):
    # do some computation
    bar.update()
    
# print report for future reference
print(bar)



Progress Bar/Percentage Indicator - Reporting CPU and memory usage

monitor (bool): default False. Monitors CPU and memory usage if True (requires 'psutil' package).


In [ ]:
n = 150000

bar = pyprind.ProgBar(n, monitor=True)
for i in range(n):
    # do some computation
    bar.update()
print(bar)


In [ ]:
n = 1500

perc = pyprind.ProgPercent(n, monitor=True)
for i in range(n):
    # do some computation
    perc.update()
print(perc)



Progress Bar/Percentage Indicator - Setting a title

title (str): default ''. A title for the progress bar


In [ ]:
n = 150000

bar = pyprind.ProgBar(n, title='My 1st Progress Bar')
for i in range(n):
    # do some computation
    bar.update()

In [ ]:
n = 1500

perc = pyprind.ProgPercent(n, title='My 1st Percent Tracker')
for i in range(n):
    # do some computation
    perc.update()



Progress Bar - Changing the default width

width (int): default 30. Sets the progress bar width in characters.


In [ ]:
n = 150000

bar = pyprind.ProgBar(n, width=10)
for i in range(n):
    # do some computation
    bar.update()

bar = pyprind.ProgBar(n, width=70)
for i in range(n):
    # do some computation
    bar.update()



Progress Bar/Percentage Indicator - Changing the output stream

stream (int): default 2. Takes 1 for stdout, 2 for stderr, or given stream object


In [ ]:
n = 150000

bar = pyprind.ProgBar(n, stream=1)
for i in range(n):
    # do some computation
    bar.update()

In [ ]:
bar = pyprind.ProgBar(n, stream=2)
for i in range(n):
    # do some computation
    bar.update()

In [ ]:
import sys

bar = pyprind.ProgBar(n, stream=sys.stdout)
for i in range(n):
    # do some computation
    bar.update()