A simple ANSI-based progress bar
Project description
progress1bar
A simple ANSI-based progress bar.
Installation
pip install progress1bar
ProgressBar
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 names, random, time
from progress1bar import ProgressBar
with ProgressBar() as pb:
pb.alias = names.get_full_name()
pb.total = random.randint(50, 100)
for _ in range(pb.total):
# simulate work
pb.count += 1
time.sleep(.09)
Executing the code above (example1) results in the following:
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.
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:
import names
from progress1bar import ProgressBar
print('Processing names...')
completed_message = 'Done processing all names'
fill = {'max_index': 9, 'max_total': 999}
with ProgressBar(index=1, total=500, completed_message=completed_message, fill=fill, clear_alias=True) as pb:
for _ in range(pb.total):
pb.alias = names.get_full_name()
# simulate work
pb.count += 1
Executing the code above (example2) results in the following:
Configure ProgressBar
to use regular expressions to determine the total
, count
and alias
attributes:
import names, random, logging
from progress1bar import ProgressBar
logger = logging.getLogger(__name__)
TOTAL_ITEMS = 325
def process_message(pb, message):
pb.match(message)
logger.debug(message)
regex = {
'total': r'^processing total of (?P<value>\d+)$',
'count': r'^processed .*$',
'alias': r'^processor is (?P<value>.*)$'
}
fill = {
'max_total': TOTAL_ITEMS
}
with ProgressBar(regex=regex, fill=fill) as pb:
last_name = names.get_last_name()
process_message(pb, f'processor is {last_name}')
total = random.randint(50, TOTAL_ITEMS)
process_message(pb, f'processing total of {total}')
for _ in range(total):
process_message(pb, f'processed {names.get_full_name()}')
Executing the code above (example3) results in the following:
Configure ProgressBar
to show and reuse progress for several iterations:
import names, random
from progress1bar import ProgressBar
TOTAL_ITEMS = 325
TOTAL_NAMES = 5
fill = {
'max_total': TOTAL_ITEMS,
'max_completed': TOTAL_NAMES
}
with ProgressBar(fill=fill) as pb:
total_names = 0
while True:
pb.alias = names.get_last_name()
pb.total = random.randint(50, TOTAL_ITEMS)
for _ in range(pb.total):
names.get_full_name()
pb.count += 1
total_names += 1
if total_names == TOTAL_NAMES:
pb.alias = ''
break
pb.reset()
Executing the code above (example4) results in the following:
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 \
/bin/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.0.tar.gz
.
File metadata
- Download URL: progress1bar-0.2.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03cdf8d0b5a68576c791999546a0b52561d5bb5196f664a49d9ffc5e71f091fa |
|
MD5 | bd4bc37e7deb62bbc7fe479a3d266e7b |
|
BLAKE2b-256 | 69ff162e16284790c6649f392df0895c73d7693e8ddcd5325caa07778fe0fa0e |
File details
Details for the file progress1bar-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: progress1bar-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.8 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 | 25bd58b1e644165273720cd8acb0cea846bb23ae1c2953e4ee2634180762b05c |
|
MD5 | 4db17dddff8c18922462179f42bc9817 |
|
BLAKE2b-256 | 4d1e404c043a71a024e486b2eca2dcd5038d98b98429ea2941a485373af61861 |