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: FgColor = FgColor.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 (ansiterminal.FgColor) – the color of the bar.

Changed in version v1.5.0: Type of bar_color changed to ansiterminal.FgColor.

pymisclib.multiprogressbar.prepare_bars(configs: list)

Print to prepare for the bars.

pymisclib.multiprogressbar.print_bars(configs: list)

Print progress bars.

pymisclib.multiprogressbar.BAR_COLORS

Color codes for progress bars.

Deprecated since version v1.5.0: Use ansiterminal.FgColor instead.

class pymisclib.multiprogressbar.SingleProgressBar(total_steps: int = 100, prefix: str = '', suffix: str = '', bar_segments: int = 25, bar_color: FgColor = FgColor.Black, decimals: int = 0, _current_step: int = 0)

Representation of a single progress bar.

A single bar consists of _prefix_ _bar_ _percentage_ _suffix_.

Changed in version v1.5.0: Type of bar_color changed to ansiterminal.FgColor.

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: FgColor = '\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