A simple ANSI-based progress bar
Project description
progress1bar
A simple 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, ticker=None)
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 thetotal
andcompleted
values; this is optional and should be used to format the progress bar appearance. The supported key values aremax_total
andmax_completed
.
regex
- A dictionary whose key values are regular expressions fortotal
,count
andalias
. 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. Thetotal
andcount
key values are required, thealias
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 ofProcessing
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.
ticker
- A integer representing unicode character to print as the progress bar ticker. Refer to unicode chart for values. Default is 9632 (black square ■).
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:
Code
import time
from progress1bar import ProgressBar
with ProgressBar(total=250, show_prefix=False, show_fraction=True) as pb:
for _ in range(pb.total):
pb.count += 1
# simulate work
time.sleep(.01)
example2
Configure ProgressBar
to display the item that is currently being processd by setting the alias
attribute, specify fill dictionary parameter to ensure the progress bar digits are displayed uniformly:
Code
import time
import names
from progress1bar import ProgressBar
print('Processing names...')
completed_message = 'Processed names'
with ProgressBar(total=75, completed_message=completed_message, clear_alias=True, show_fraction=False, show_prefix=False) as pb:
for _ in range(pb.total):
pb.alias = names.get_full_name()
# simulate work
time.sleep(.08)
pb.count += 1
example3
Configure ProgressBar
with a non-default ticker, and use regular expressions to determine the total
, count
and alias
attributes:
Code
import random
import names
from progress1bar import ProgressBar
regex = {
'total': r'^processing total of (?P<value>\d+)$',
'count': r'^processed .*$',
'alias': r'^processor is (?P<value>.*)$'
}
with ProgressBar(ticker=9473, regex=regex) as pb:
pb.match(f'processor is {names.get_full_name()}')
total = random.randint(500, 1000)
pb.match(f'processing total of {total}')
for _ in range(total):
pb.match(f'processed {names.get_full_name()}')
example4
Configure ProgressBar
to show and reuse progress for several iterations:
Code
import random
import time
import names
from progress1bar import ProgressBar
TOTAL_ITEMS = 800
ITERATIONS = 4
print(f'Execute {ITERATIONS} iterations of varying totals:')
with ProgressBar(show_prefix=False, show_fraction=False) as pb:
iterations = 0
while True:
if iterations == ITERATIONS:
pb.alias = ''
pb.complete = True
break
pb.alias = names.get_full_name()
pb.total = random.randint(500, TOTAL_ITEMS)
for _ in range(pb.total):
names.get_full_name()
pb.count += 1
iterations += 1
pb.reset()
time.sleep(.4)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file progress1bar-0.2.4.tar.gz
.
File metadata
- Download URL: progress1bar-0.2.4.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f350f3e1e7ac1fd5f5459dbc5c01d42e91b5f65253875d353ea01a3a82fa4693 |
|
MD5 | ba8071206eee9f7f7eb77d437fe20c4e |
|
BLAKE2b-256 | 7abb506e0ab56da85b869151d60b0177e8bb92a4c3d533591a735354df24689f |
File details
Details for the file progress1bar-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: progress1bar-0.2.4-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c80ca5c4728fb5cb29ec10524eeafa6b642a6ec9d9b9912c88b4672270535c39 |
|
MD5 | 018c2c336923a3572c58b9460cd7dc9a |
|
BLAKE2b-256 | 6ca1a6c1afbf67109e2a1409be462aca4ed0220dc942e8928140a54b9f7ff7a1 |