Progress bar for terminal
Project description
Awesome progress bar
It's a progress bar for the terminal. But why it is awesome?
- It has thread mode. This way progress bar can run in the parallel.
- It's animated with ASCII characters.
- It also measures elapsed time.
- It's user-friendly and customizable.
Why does progress bar need to be run in the parallel mode?
The bar should be updated when it is time to. Imagine we are doing something in the for
loop and each iteration we update its state. But each iteration can take different amount
of time. And each iteration can be longer than 1 minute. And without threads the animation
would have non-constant amount of FPS.
How to use
Initialization
Parameters:
- total: Amount of iterations.
- prefix: A short message before the progress bar. Default is 'Progress'.
- suffix: A short message after the progress bar. Default is 'Complete'.
- fill: A character that will be used as progress bar filler.
- bar_length: The length of the whole string (including prefix, spinner, progress bar, percents and suffix). Default is equal to the minimum between terminal's width and 100.
- update_period: The duration of pause between iterations in seconds. Default is 0.1. Works only if use_thread is True.
- use_time: If True there will be an information about elapsed time in the center of the progress bar written in time_format format. Default is True.
- time_format: String, that should include hh, mm or/and ss. hh will be replaced with amount of elapsed hours, mm - minutes, ss - seconds. Default is 'mm:ss'.
- use_thread: If True ProgressBar will create extra thread. Default is True.
- spinner_type: One of
['sb', 'db', 's']
. With'sb'
progress bar will print spinner consisting of 1 Braille pattern.'db'
- 2 Braille patterns.'s'
- a slash. Default is'sb'
. - use_spinner: If True the spinner will be shown. Default is True.
- new_line_at_end: If True the caret will go to the new line at the end. Default it True.
- use_eta: If True the information about approximate remaining time will be printed. Default is False.
- eta_format: The format of ETA. Similar to the time_format. Default is 'mm:ss'.
Methods
- iter(append): Used for tracking the progress.
- stop(): Stops the bar in the thread mode.
- wait(): Blocks the program until bar is dead.
bar.iter(append='')
Used for tracking the progress.
- In the thread mode only increases the number of iteration.
- Without extra thread
bar.iter()
prints the bar each time user call it.
Parameters:
- append: A string to append after the bar. The appended text doesn't effect on the progress bar width.
bar.stop()
Stops the bar if it run in the thread mode.
If the user doesn't stop the bar, it will update endlessly. Therefore, I recommend updating
the bar using bar.iter()
in the try/except block, and calling bar.stop()
in the except
or finally
blocks.
bar.wait()
Blocks the program until bar is dead.
The bar updates every update_period seconds in the thread mode. Hence, there can be a small
delay between last calling bar.iter()
and next try for printing something. So, if you want to
print anything after the progress is done be aware to use bar.wait()
Examples
from awesome_progress_bar import ProgressBar
import time
total = 133
bar = ProgressBar(total, bar_length=50)
try:
for x in range(total):
time.sleep(0.1)
bar.iter(' Appended')
except:
bar.stop()
bar.wait()
print('Bar is done')
# Progress: |====== 00:14 ======| 100.00% Complete Appended
# Bar is done
from awesome_progress_bar import ProgressBar
bar = ProgressBar(100, prefix='Prefix', suffix='Suffix', bar_length=50)
# Prefix: вЎ† |=> 00:00 | 4.51% Suffix
bar = ProgressBar(100, fill='#', use_time=False, bar_length=50, use_spinner=False)
# Progress: |> | 3.01% Complete
bar = ProgressBar(100, time_format='hhh mmmin sss', use_eta=True, bar_length=70, spinner_type='s')
# Progress: \ |==> 00h 00min 01s | 7.52% ETA: 00:12
bar = ProgressBar(100, bar_length=70, spinner_type='db')
# Progress: вў€вЎ± |=========> 00:03 | 25.56% Complete
Feel free to suggest ideas to improve this package in the GitHub's Issues section.
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
Hashes for awesome-progress-bar-1.6.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc4506faa1822d119032efa7cb6de1bd7bbd6d056162862fc6708e62ff0b4043 |
|
MD5 | 878c50b0b529564541bd13b423a2b486 |
|
BLAKE2b-256 | 2a91ca32a2ce24526faec59e19e6b298e6e92397e2feb93bfd8097a1f801eadf |
Hashes for awesome_progress_bar-1.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aff34b69f858740894e350834469486d667c3df5801b71716ce46f74375ad31 |
|
MD5 | 63c734779354323b50c05d8761865792 |
|
BLAKE2b-256 | 054a7551dab06011f65c8d1cfaef019e844d4afd8d3d3fcc0e9864307f1ae3d1 |