multiprogressbar
Print multiple progress bars to the console.
New Interface
Example:
Total │████│ 100%
Proc1 │██████████│ 100% 1
Proc2 │██████████│ 100% two
Proc3 │██████████│ 100% III
Proc4 │████████████│ 100.0% four
Classic Interface
The configuration of the bars is handled through a list of dictionaries. Each dictionary contains the parameters for a single progress bar.
Before the bars are shown, prepare_bars() must be called to make room for
the bars on the console.
Each time a bar is updated, print_bars() is called to update the console
output.
Bar example
A simple example shows a bar for the entire process and a second bar for individual progress steps below the first bar.
This is an example:
Total |------------------------------| 0% Writing
|███████████████---------------| 50.9% /tmp3muil9sc/0000000000000000.tmp
from multiprogressbar import prepare_bars, print_bars
config = [
{
'current_iteration': 0,
'total_iterations': 5,
'prefix': 'Total',
'suffix': 'Writing',
'decimals': 0,
'bar_length': 30},
{
'current_iteration': 509,
'total_iterations': 1000,
'prefix': ' ',
'suffix': '/tmp3muil9sc/0000000000000000.tmp',
'decimals': 1,
'bar_length': 30},
]
prepare_bars(config)
print_bars(config)
- pymisclib.multiprogressbar.print_single_bar(current_iteration: int, total_iterations: int, prefix: str = '', suffix: str = '', decimals: int = 1, bar_length: int = 80, bar_color: BAR_COLORS = BAR_COLORS.Black)
Output a single progress bar to stdout.
- Parameters:
current_iteration (int) – the current iteration
total_iterations (int) – the total number of iterations
prefix (str) – a string that will be output before the bar
suffix (str) – a string that will be output after the bar
bar_length (int) – the length of the bar in characters
bar_color (BAR_COLORS) – the color of the bar.
- pymisclib.multiprogressbar.prepare_bars(configs: list)
Print to prepare for the bars.
- pymisclib.multiprogressbar.print_bars(configs: list)
Print progress bars.
- class pymisclib.multiprogressbar.BAR_COLORS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Colors and the ANSI output_format strings used to create them.
- Black = '\x1b[30m'
- Blue = '\x1b[34m'
- BrightBlack = '\x1b[90m'
- BrightBlue = '\x1b[94m'
- BrightCyan = '\x1b[96m'
- BrightGreen = '\x1b[92m'
- BrightMagenta = '\x1b[95m'
- BrightRed = '\x1b[91m'
- BrightWhite = '\x1b[97m'
- BrightYellow = '\x1b[93m'
- Cyan = '\x1b[36m'
- Green = '\x1b[32m'
- Magenta = '\x1b[35m'
- Red = '\x1b[31m'
- White = '\x1b[37m'
- Yellow = '\x1b[33m'
- class pymisclib.multiprogressbar.SingleProgressBar(total_steps: int = 100, prefix: str = '', suffix: str = '', bar_segments: int = 25, bar_color: BAR_COLORS = BAR_COLORS.Black, decimals: int = 0, _current_step: int = 0)
Representation of a single progress bar.
A single bar consists of _prefix_ _bar_ _percentage_ _suffix_.
- bar() str
Return the bar only (no prefix, suffix, or percent) as a string.
- color_string() str
Representation of the entire bar (including pre- and suffix) with color code.
- Returns:
Formatted string.
- Rtype str:
- percent_str() str
Return the percentage of the bar filled as a formatted string.
- print(color: bool = True)
Output the entire bar to sys.stdout.
- Parameters:
color (bool) – True to output_format bar with color information, False without.
- bar_color: BAR_COLORS = '\x1b[30m'
Color of the bar.
- bar_segments: int = 25
Number os segments in the bar when completed.
- property current_step: int
Current step of the bar on the way towards total_steps.
- decimals: int = 0
Number of decimals to use in displaying the percentage completed.
- property percent: float
Degree to which the bar is filled as a number 0..1.
- Returns:
Fraction of the bar that is filled. Valid range [0..1].
- Rtype float:
- prefix: str = ''
Text before the bar.
- suffix: str = ''
Text after the bar.
- total_steps: int = 100
Steps required to complete progress.
- class pymisclib.multiprogressbar.MultiProgressBar(bars: list[~pymisclib.multiprogressbar.SingleProgressBar] = <factory>, terminal: ~pymisclib.ansiterminal.AnsiTerminal = <factory>)
Multiple SingleProgressBars on top of each other.
- print(color: bool = True, first: bool = False)
Output the entire multibar to sys.stdout.
- Parameters:
color (bool) – True to output_format bar with color information, False without.
- bars: list[SingleProgressBar]
- property current_steps: list[int]
Return a list of current bar steps.
- Returns:
A list of the current step for each bar.
- Rtype list[int]:
- terminal: AnsiTerminal