Skip to main content

A customizable ANSI-based progress bar

Project description

progress1bar

build coverage vulnerabilities PyPI version python

A customizable ANSI-based progress bar.

Installation

pip install progress1bar

ProgressBar

ProgressBar(
    total=None,
    fill=None,
    regex=None,
    completed_message=None,
    clear_alias=False,
    show_prefix=True,
    show_fraction=True,
    show_percentage=True,
    show_duration=False,
    show_complete=True,
    ticker=None,
    use_color=True,
    show_bar=True)
Documentation

total - An integer for the total number of items the progress bar will show that need to be completed.

fill - A dictionary whose key values are integers that dictate the number of leading zeros the progress bar should add to the total and completed values; this is optional and should be used to format the progress bar appearance. The supported key values are max_total and max_completed.

regex - A dictionary whose key values are regular expressions for total, count and alias. The regular expressions will be checked against the log messages intercepted from the executing function, if matched the value will be used to assign the attribute for the respective progress bar. The total and count key values are required, the alias key value is optional.

completed_message - A string to designate the message the progress bar should display when complete. Default is 'Processing complete'

clear_alias - A boolean to designate if the progress bar should clear the alias when complete.

show_prefix - A boolean to designate if the prefix of Processing should be printed prefixing the progress bar.

show_fraction - A boolean to designate if the fraction should be printed with the progress bar.

show_percentage - A boolean to designate if the percentage should be printed with the progress bar.

show_duration - A boolean to designate if the duration should be printed after progress bar execution.

show_complete - A boolean to designate if the completed message is to be displayed upon progress bar completion.

ticker - A integer representing unicode character to print as the progress bar ticker. Refer to unicode chart for values. Default is 9632 (black square ■).

use_color - A boolean to designate if the progress bar should be displayed with color. Default is True.

show_bar - A boolean to designate if the progress bar tickers should be printed.

Attributes

count - An integer attribute to increment that designates the current count. When count reaches total the progress bar will show complete.

alias - A string attribute to set the alias of the progress bar.

Functions

reset()

Reset the progress bar so that it can be used again. It will maintain and show the number of times the progress bar has been used.

Examples

Various examples are included to demonstrate the progress1bar package. To run the examples, build the Docker image and run the Docker container using the instructions described in the Development section.

example1

The ProgressBar class is used to display function execution as a progress bar. Use it as a context manager, and simply set the .total and .count attributes accordingly. Here is an example:

import time
from progress1bar import ProgressBar

with ProgressBar(total=250) as pb:
    for _ in range(pb.total):
        pb.count += 1
        # simulate work
        time.sleep(.01)

example

example2

Configure ProgressBar to display an alias for the item that is currently being processed by setting the alias parameter:

import time
from faker import Faker
from progress1bar import ProgressBar

kwargs = {
    'total': 75,
    'completed_message': 'Processed names complete',
    'clear_alias': True,
    'show_fraction': False,
    'show_prefix': False,
    'show_duration': True
}
with ProgressBar(**kwargs) as pb:
    for _ in range(pb.total):
        pb.alias = Faker().name()
        # simulate work
        time.sleep(.08)
        pb.count += 1

example

example2b

Configure ProgressBar to display an alias for the item that is currently being processed, but do not print out the ticker, instead show percentage and fraction complete:

from faker import Faker
from progress1bar import ProgressBar

kwargs = {
    'total': 575,
    'clear_alias': True,
    'show_complete': False,
    'show_prefix': False,
    'show_duration': True,
    'show_bar': False
}
with ProgressBar(**kwargs) as pb:
    for _ in range(pb.total):
        pb.alias = Faker().sentence()
        # simulate work
        pb.count += 1

example

example3

Configure ProgressBar with a custom ticker, show duration, do not use color, and use regular expressions to determine the total, count and alias attributes:

import random
from faker import Faker
from progress1bar import ProgressBar

kwargs = {
    'ticker': 9733,
    'regex': {
        'total': r'^processing total of (?P<value>\d+)$',
        'count': r'^processed .*$',
        'alias': r'^processor is (?P<value>.*)$'
    },
    'use_color': False,
    'show_duration': False
}
with ProgressBar(**kwargs) as pb:
    pb.match(f'processor is {Faker().name()}')
    total = random.randint(500, 750)
    pb.match(f'processing total of {total}')
    for _ in range(total):
        pb.match(f'processed {Faker().name()}')

example

example4

Configure ProgressBar to show and reuse progress for several iterations:

import random
import time
from faker import Faker
from progress1bar import ProgressBar

TOTAL_ITEMS = 300
ITERATIONS = 4
kwargs = {
    'show_prefix': False,
    'show_fraction': False,
    'show_duration': True
}
print(f'Execute {ITERATIONS} iterations of varying totals:')
with ProgressBar(**kwargs) as pb:
    iterations = 0
    while True:
        if iterations == ITERATIONS:
            pb.alias = ''
            pb.complete = True
            break
        pb.alias = Faker().name()
        pb.total = random.randint(100, TOTAL_ITEMS)
        for _ in range(pb.total):
            Faker().name()
            pb.count += 1
        iterations += 1
        pb.reset()
        time.sleep(.4)

example

Programs using progress1bar

Development

Clone the repository and ensure the latest version of Docker is installed on your development server.

Build the Docker image:

docker image build \
-t progress1bar:latest .

Run the Docker container:

docker container run \
--rm \
-it \
-v $PWD:/code \
progress1bar:latest \
bash

Execute the build:

pyb -X

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

progress1bar-0.4.2.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

progress1bar-0.4.2-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file progress1bar-0.4.2.tar.gz.

File metadata

  • Download URL: progress1bar-0.4.2.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for progress1bar-0.4.2.tar.gz
Algorithm Hash digest
SHA256 ff6dfe10c12f774efaa0f2141dffcae13c4270b86923bf2f545145f9930f11c2
MD5 47ab3cac675959e46b4be596527223a8
BLAKE2b-256 e5229c248e14aeed264f7805b51993368bae4f7b2a1062cba20ab92c56f9ed91

See more details on using hashes here.

File details

Details for the file progress1bar-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for progress1bar-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f74aede94193f5ea3847d8750358846d03997802cfa5c90e1629f9728aa55da
MD5 91f7fc64c6cbc464920010cdd9cb0717
BLAKE2b-256 57895d75a60e10ecf18c282e6f5552cd9388e7548fe5f2798547fa53e7f5463e

See more details on using hashes here.

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