Simple and easy to use progress bar to monitor the progress in required task. No specific package requirement, can run on any Python 3 environment.
Find the complete guide how to use this library step by step. Read medium post here.
-
Clone this repository:
git clone https://github.com/tarunk04/progress-bar-python.git
or click
Download ZIP
in right panel of repository and extract it. -
Copy
progress.py
into your working directory. -
Read to go.
Note: I will soon release python package for this repository.
-
Import
from progress import Progress as P
-
Create instance with a bar and maximum value 70
p = P(70, mode="bar")
-
Create elements for progress bar to match example progress bar.
# defining progress bar elements epoch = P.Element("Epoch", 0) progress_time = P.ProgressTime(postfix="/epoch") batch = P.Element("Batch", 0, display_name='hide', max_value=70, value_display_mode=1) loss = P.Element("Loss", 0) acc = P.Element("Acc", 0) # progress bar [====> ] bar = P.Bar()
Syntax for P.Element, P.Bar, P.FillBar and P.ProgressTime objects:
# Element P.Element(name, initial_value, max_value=None, display_name="normal", value_display_mode=0, separator=":") """ Element Examples: "Epochs: 1" "Epochs: 1/10" "1 Epochs" Parameters: name (str): name for displaying in progress for the element initial_value (float): initial value for the element max_value (int): maximum value that element can take. Note only required in display_mode =1. display_name (str): value can take form ["normal","reverse","hide"]. In "reverse" mode name will displayed after value. "hide" will hide the name from progress value_display_mode (int): [0,1].default 0. Format "Epoch: 1". For 1 format "Epoch 1/10". separator (char): default ":". can be changed according to preference f (int) : Default None. floating point precision. """ # Bar P.Bar(max_value=None, bar_len=20, bar_marker="=", bar_pointer=">") """ Element Examples: [======> ] [-------> ] Parameters: max_value (int): not required. it will be automatically taken from Progress object. bar_len (int): default 20. length for the bar. [==========> ]. bar_marker (char): default "=" can be changed according to preference. bar_marker (char): default ">" can be changed according to preference. """ # FillBar P.FillBar(mode=None, max_value=None, bar_len=25): """ Bar style Fill Example: ●●●●●●●○○○○○○○ ■■■■■■□□□□□□□□ |█████○○○○○○○○○| Parameters: mode (char, str, int): Default: "normal", Mode can be 'circle' 'c' or 0, 'square' 's' or 1 and 'normal' 'n' or 2. max_value (int): not required. it will be automatically taken from Progress object. bar_len (int): default 20. length for the bar. [==========> ]. """ # ProgressTime P.ProgressTime(postfix="") """ Element Examples: "100ms" "112s/epochs" Parameters: postfix (str): string after time """
-
Format/ combine all element. Note: You can create elements in any order but while combining order matters.
# Formating progress bar p = p(epoch)(bar)(batch)(progress_time)("- ")(loss)("- ")(acc) # Alternate syntax p = p + epoch + bar + batch + progress_time + "- " + loss + "- " + acc """ * Any number of elements can be added. Use Bar and ProgressTime only once otherwise it may cause unexpected issues. * To just add text anywhere in between simply add p(elemt1)(bar)("Sample Text")(elemt2)....("Some More Text")...(elemtN) """
you can see the final format of progress bar using
p.get_format()
: -
Finally lets see how to update the progress bar:
p.initialize() # initializing progress bar for e in range(10): for i in range(70): """ Other code block ---------------- """ # updating progress bar elements. Values each elements can be updated by just passing the # new values like below loss(random.randint(1000, 5000)/10000) # passing dummy number acc(random.randint(1, 100)/100) # passing dummy number batch(i+1) epoch(e+1) # rendering progress bar p.update(step = 1) # Sleep. Not required in actual usage of progress bar. time.sleep(0.1) # setting new line for next epoch. Otherwise the new epoch progress will overwrite the old one. p.set_cursor_position()
- Done 😎. Enjoy ✨.
Tarun Kumar
Author's Note
The author is not responsible for any misuse the program. Any contribution or suggestions are most welcome. Read the LICENSE carefully.
The MIT License, see the included, see the License file.