lowbar
The simplest no-nonsense progress bar for python.
lowbar is a blazing fast module with zero dependencies for displaying a progress bar in the terminal. It has a low number of features and a simple codebase, hence the name lowbar.
lowbar has:
- Automatic resizing
- Manual progress management
- Automatic progress management (As an iterable)
- Text logging
- Bar styling
- Low overhead
- Small size ( < 150 lines)
lowbar doesn't have:
- Nested bars
- Fancy animations
- ETA calculations
Requirements
- Python 3.7 or above. lowbar may support earlier versions, but this has not been tested.
- A console that supports line feed
\nand carriage return\r.
Installation
Install the latest stable release:
pip install lowbar
Or the development version:
pip install git+https://github.com/AnnikaV9/lowbar
The sections below document the development version in this repository. For the stable release docs, refer to the PyPi page.
Usage
Once you have lowbar installed, you can import it like any other module:
from lowbar import lowbar
And initialize the bar:
bar = lowbar()
To make the bar visible and set at 0%:
bar.new()
After completing some tasks, we can increase the bar's completion percentage:
bar.add(20)
If we have a known number of tasks, lowbar can automatically calculate the percentage for us:
bar.next(tasks)
We can also set the completion percentage instead of adding to it:
bar.update(50)
Using print() or other similar functions will push the bar up, which doesn't look nice. To log messages without affecting the bar:
bar.log("Hello World!")
And finally, to clear the bar completely:
bar.clear()
Here's an example usage of the bar:
tasks = 10
bar.new()
for i in range(tasks):
time.sleep(2) # task
bar.log(f"Task {i+1} completed")
bar.next(tasks)
bar.clear()
print("Tasks complete!")
You don't even need a loop:
bar.new()
time.sleep(1) # task
bar.add(10)
time.sleep(2) # task
bar.add(10)
time.sleep(2) # task
bar.update(100)
bar.clear()
print("Tasks complete!")
The bar can also be used with a context manager. It will automatically run new() at the start and clear() when exiting:
with lowbar() as bar:
time.sleep(1) # task
bar.add(50)
time.sleep(3) # task
bar.add(50)
print("Tasks complete!")
To make things simpler, you can wrap lowbar around range() and turn it into an iterable. It will automatically calculate how much to increase the percentage by every loop:
for i in lowbar(range(100)):
time.sleep(0.5) # task
Pass an integer and lowbar will convert it into a range object for you:
for i in lowbar(100):
time.sleep(0.5) # task
[!NOTE] You can't use
log()when using lowbar as an iterable.
You can also change the load fill and blank fill chars:
bar = lowbar(load_fill="O", blank_fill=".")
Or add a description text to the left side of the bar:
bar = lowbar(desc="Downloading...")
[!NOTE] If the console is too small to accommodate both the bar and the description text, the text will be hidden.
Reference
__init__()
Called when the lowbar object is created.
| Parameter | Type | Description | Default |
|---|---|---|---|
bar_iter |
range |
A range object that lowbar will iterate through when __iter__() is called. If an integer is provided, lowbar converts it into a range object. |
0 |
load_fill |
str |
A single-character string used to fill the bar as it loads. | "#" |
blank_fill |
str |
A single-character string used to fill the unloaded part of the bar. | "-" |
desc |
str |
Text displayed to the left of the bar. If the console is too small, this text will be hidden. | "" |
remove_ends |
bool |
Hides the characters at both ends of the bar ([ & ]). |
False |
keep_receipt |
bool |
Prevents lowbar from automatically clearing the bar after completion (Only applicable when used as an interable or with context manager). |
False |
new()
Alias for update(0).
update()
Set the completion percentage and refreshes the bar, resizing if the console size changes.
| Parameter | Type | Description | Default |
|---|---|---|---|
percentage |
int |
The percentage to set as the completed progress. (0-100) | No default |
add()
Add to the completion percentage and refreshes the bar, resizing if the console size changes.
| Parameter | Type | Description | Default |
|---|---|---|---|
percentage |
int |
The percentage to add to the completed progress. | No default |
next()
Similar to add(), but calculates the percentage to add based on the total number of tasks.
| Parameter | Type | Description | Default |
|---|---|---|---|
tasks |
int |
The total number of tasks to complete. | No default |
log()
Logs text to the console without affecting the bar.
| Parameter | Type | Description | Default |
|---|---|---|---|
text |
str |
The text to log. Other types must be converted to strings before. | No default |
clear()
Clears the currently active bar.
Contributing
All contributions are welcome!
If you wish to report a bug or suggest a feature, open an issue.
You can also make a pull request directly if you already have the fix for a bug.
See CONTRIBUTING.md for guidelines to follow.
Contributors are listed in CONTRIBUTORS.md.
License
This project is licensed under the MIT License.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lowbar-2.2.0.tar.gz.
File metadata
- Download URL: lowbar-2.2.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1fb088857913219e6f475b2917eb8c752de54398410422eebce1dce708addfa
|
|
| MD5 |
2e5a268d2bb7124f6a945158607afc48
|
|
| BLAKE2b-256 |
b12c925857ce54b51ebf3e1c681b46612e69880324710390705b54e439c706fd
|
File details
Details for the file lowbar-2.2.0-py3-none-any.whl.
File metadata
- Download URL: lowbar-2.2.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa1f3eefe4d49cb247bc98b857e7027037e9a5b067a7350f90b35af4aa539338
|
|
| MD5 |
07ab8678f7d5bcbddb5e49324178ee6b
|
|
| BLAKE2b-256 |
d8eacd27070455a8f9c7cc4b4e030e6d7ccee753aac9f110344e229ec1239570
|