Enlighten Progress Bar
Enlighten Progress Bar is a console progress bar module for Python. It allows writing to stdout and stderr without any redirection, offering features for single or multiple progress bars, counters, and status bars, with experimental support for Jupyter Notebooks. As of version 1.14.1, it is actively maintained with regular updates and bug fixes.
Warnings
- gotcha Terminal output can become scrambled or cut off if the number of progress bars exceeds terminal height, or if other threads/processes write to standard streams simultaneously with a resize event.
- gotcha Enlighten does not work natively in the PyCharm Python console due to `sys.stdout` not referencing a valid TTY. It requires terminal emulation for 'Run' or 'Debug' modes.
- gotcha Progress bars created with a `Manager` might remain visible after `close()` is called if `leave=True` (the default) or `clear=True` is not explicitly used.
- gotcha Failing to call `manager.stop()` at the end of your program can leave progress bars on the terminal, consume resources, and prevent proper cleanup.
- breaking Prior to version 1.12.0, the `elapsed` time on counters might continue to increment even after the counter was conceptually 'closed' or reached its total, leading to incorrect time measurements.
- breaking Before version 0.14.0, the column position of the progress bar was not preserved when updating, always returning to the start of the line. This behavior changed to preserve column position.
Install
-
pip install enlighten
Imports
- get_manager
from enlighten import get_manager
- Counter
from enlighten import Counter
- Justify
from enlighten import Justify
Quickstart
import time
import enlighten
# Get a manager instance to handle multiple progress bars
manager = enlighten.get_manager()
# Create two counters/progress bars
ticks = manager.counter(total=100, desc='Ticks', unit='ticks')
tocks = manager.counter(total=20, desc='Tocks', unit='tocks')
for num in range(100):
time.sleep(0.05) # Simulate work
print(f"Working on item {num}") # Output outside progress bars
ticks.update()
if not num % 5:
tocks.update()
# Ensure all progress bars are cleaned up from the terminal
manager.stop()
print("Process complete!")