progressbar
The `progressbar` library (version 2.5) provides text-based progress bars for long-running operations in Python. This version is largely unmaintained and is compatible only with Python 2. For modern Python projects, the actively maintained `progressbar2` library is recommended, which offers backward compatibility and Python 3 support.
Warnings
- breaking The `progressbar` (version 2.5) library is Python 2 only. It will not run on Python 3 environments without significant modifications or, more practically, replacement. Python 2 reached its end-of-life in 2020.
- deprecated The original `progressbar` library is abandoned and unmaintained. Its development ceased, leading to the creation of `progressbar2` as a direct, backward-compatible fork.
- gotcha Installing `progressbar` via `pip install progressbar` will install the old, abandoned Python 2-only version (2.5). Users intending to use an actively maintained progress bar library for Python 3 should explicitly install `progressbar2`.
- gotcha Progress bars might not update visually during runtime in certain environments (e.g., some IDEs, Jupyter notebooks, or when long-running tasks block the event loop in GUI applications). This can lead to the bar appearing only at the end or updating erratically.
Install
-
pip install progressbar -
pip install progressbar2
Imports
- ProgressBar
import progressbar; pbar = progressbar.ProgressBar()
Quickstart
import time
import progressbar
def main():
print("Using progressbar (v2.5) for demonstration (Python 2 example if run directly)")
print("**It is HIGHLY recommended to use 'progressbar2' instead: pip install progressbar2**\n")
# This quickstart pattern is derived from progressbar2 examples,
# which aims for backward compatibility with the original 'progressbar'.
widgets = [
'Test: ', progressbar.Percentage(),
' ', progressbar.Bar(marker=progressbar.RotatingMarker()),
' ', progressbar.ETA(),
' ', progressbar.FileTransferSpeed(),
]
# For Python 2, range(100) is fine. For Python 3, use list(range(100)) or ensure xrange behavior.
# As this library is Python 2, simple range is shown.
bar = progressbar.ProgressBar(widgets=widgets, maxval=100).start()
for i in range(100):
# Simulate some work
time.sleep(0.01)
bar.update(i + 1)
bar.finish()
print("\nExample complete.")
if __name__ == '__main__':
main()