Python Progressbar2 Library
progressbar2 is an actively maintained Python library designed to provide visual, text-based progress bars for long-running operations in CLI applications. It is a fork of the original `progressbar` package, aiming for backwards compatibility while offering enhanced features and ongoing development. The current stable version is 4.5.0.
Warnings
- gotcha The installed package is named `progressbar2`, but you must import `progressbar` in your Python code. Attempting to `import progressbar2` will result in an `ImportError`.
- gotcha In Jupyter notebooks or environments that buffer `sys.stdout`, the progress bar output might appear mixed or delayed.
- gotcha When using Jetbrains IDEs (like PyCharm), especially for advanced features like `MultiBar` support or to prevent interleaved output between the progress bar (which often writes to stderr) and `print` statements (writing to stdout), you may need to enable 'Enable terminal in output console' in your run configuration. Alternatively, redirect the progress bar to `sys.stdout`.
Install
-
pip install progressbar2
Imports
- ProgressBar
from progressbar import ProgressBar
- widgets
from progressbar import Bar, Percentage, ETA
- progressbar
import progressbar
Quickstart
import time
import progressbar
MAX_VALUE = 100
with progressbar.ProgressBar(max_value=MAX_VALUE) as bar:
for i in range(MAX_VALUE):
# Simulate a task
time.sleep(0.02)
bar.update(i + 1)
print("Task completed!")