Skip to main content

Light progress reporting tool for Python

Project description

This is a progress reporting tool for Python.

ProgressBar.iteration(range(42), lambda item: sleep(0.01))
# [▉..............................] 1% (1/42)
# [███████████████▉...............] 50% (21/42)
# [███████████████████████████████] 100% (42/42)

Installation

pip install light-progress

Examples

Import

from time import sleep
from light_progress import ProgressBar

Pattern 1

Call start() forward() and finish() yourself.

n = 42
progress_bar = ProgressBar(n)
progress_bar.start()

for item in range(n):
    sleep(0.01)
    progress_bar.forward()

progress_bar.finish()

Pattern 2

You can execute a iteration within with statement. You don’t have to call start() and finish() explicitly.

n = 42
with ProgressBar(n) as progress_bar:
    for item in range(n):
        sleep(0.01)
        progress_bar.forward()

Pattern 3

Transfer iteration. You don’t have to call any ProgressBar methods yourself.

ProgressBar.iteration(range(42), lambda item: sleep(0.01))

Pattern 4

Transfer generation. You don’t have to call any ProgressBar methods yourself.

for item in ProgressBar.generation(range(42)):
    sleep(0.01)

Colors

status

color

In progress

Blue

Success

Green

Failure

Red

Customize

from light_progress import Colors, MessageType
colors = {
    MessageType.COURSE: Colors.YELLOW,
    MessageType.COMPLETE: Colors.BLUE,
}
ProgressBar.iteration(range(100), lambda item: sleep(0.01), colors=colors)

Widgets

ProgressBar can change its display format using widget.

from light_progress import widget
widgets = [widget.Bar(bar='=', tip='-'),
           widget.Percentage(),
           widget.Num()]

ProgressBar.iteration(
    range(42), lambda item: sleep(0.01), widgets=widgets)

# [===============-...............] 50% (21/42)
widgets = [widget.Percentage(),
           widget.Num(),
           'loading...',
           widget.Bar(bar='#', tip='>')]

ProgressBar.iteration(
    range(42), lambda item: sleep(0.01), widgets=widgets)

# 50% (21/42) loading... [###############>...............]

Formats

format_str = '{} {} ({})'

widgets = [widget.Bar(), widget.Percentage(), widget.Num()]
ProgressBar.iteration(
    range(100),
    lambda item: sleep(0.01),
    widgets=widgets,
    format_str=format_str)

# [███████████████████████████████] 100% (100/100)
format_str = '{} *** {} *** ({})'

widgets = [widget.Bar(), widget.Percentage(), widget.Num()]
ProgressBar.iteration(
    range(100),
    lambda item: sleep(0.01),
    widgets=widgets,
    format_str=format_str)

# [███████████████████████████████] *** 100% *** (100/100)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

light-progress-0.7.0.0.tar.gz (6.3 kB view hashes)

Uploaded Source

Built Distribution

light_progress-0.7.0.0-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page