Skip to main content

The simplest no-nonsense progress bar for python.

Project description

lowbar

The simplest no-nonsense progress bar for python


This GIF's playback speed is slower than the actual demo execution

demo.py

# All the sleep calls would be tasks to
# complete in a real program

import lowbar, time, random
bar = lowbar.LowBar()
completion = 0
for i in range(10): time.sleep(random.random()) bar.update_smooth(completion) bar.log(f"Task {i+1} completed") completion += 10 bar.clear()
print("\nRunning checks...") bar.update(0) time.sleep(1) bar.update_smooth(10) time.sleep(2) bar.update_smooth(40) time.sleep(2) bar.update_smooth(100) bar.clear() print("Tasks complete!")



Introduction

lowbar is a blazing fast module with zero dependencies for displaying a progress bar in the terminal. It's extremely simple with a low amount of code, hence the name lowbar.



Installation

Install the latest stable release:

pip install lowbar

Or build the development version:

git clone https://github.com/AnnikaV9/lowbar.git
cd lowbar
pip install build hatchling
python3 -m build -w
pip install dist/lowbar-*-py3-none-any.whl


Usage

Once you have lowbar installed, you can import it like any other module:

import lowbar

And initialize the bar:

bar = lowbar.LowBar()

To make the bar visible, simple update the completion percentage:

bar.update(0)

We start with 0 since our program hasn't completed anything yet.


After completing some tasks, we can increase the bar's completion percentage:

bar.update(20)

The above function will immediately move the bar to 20%. To use a more smoother but slower animation:

bar.update_smooth(40)

Note: update_smooth() will add a 5 ms delay to every percentage increment, which may cause your program to become slow if you call lowbar multiple different times. A full bar will take half a second to fill up. If you value your program's speed, it's best to stick with update()


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:

bar = lowbar.LowBar()

completion = 0
for i in range(10):
    time.sleep(2) # This would be replaced with an actual task
    bar.update_smooth(completion)
    bar.log(f"Task {i+1} completed")
    completion += 10
bar.clear()

print("Tasks complete!")

You don't even need a loop:

bar = lowbar.LowBar()

bar.update(0)
time.sleep(1)
bar.update_smooth(10)
time.sleep(2)
bar.update_smooth(40)
time.sleep(2)
bar.update_smooth(100)
bar.clear()

print("Tasks complete!")

The bar can also be used with a context manager. This will automatically start the bar at 0% and clear the bar when exiting:

with lowbar.LowBar() as bar:
    bar.update(10)
    time.sleep(2)
    bar.update_smooth(100)

print("Tasks complete!")

You can change the load fill and blank fill chars as well:

bar = lowbar.LowBar(bar_load_fill="O", bar_blank_fill=".")


Contributing

All contributions are welcome!

If you wish to report a bug or suggest a feature, open an issue.

If you already have a fix for a bug, make a pull request directly.

You can also vote on already suggested features.

See CONTRIBUTING.md for guidelines to follow.

Contributors are listed in CONTRIBUTORS.md.



License

MIT License

Copyright (c) 2022 AnnikaV9

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lowbar-1.1.3.tar.gz (8.3 kB view hashes)

Uploaded Source

Built Distribution

lowbar-1.1.3-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

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