wolph / python-progressbar

Progressbar 2 - A progress bar for Python 2 and Python 3 - "pip install progressbar2"

Home Page:http://progressbar-2.readthedocs.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Text progress bar library for Python.

Build status:

python-progressbar test status

Coverage:

image

Install

The package can be installed through pip (this is the recommended method):

pip install progressbar2

Or if pip is not available, easy_install should work as well:

easy_install progressbar2

Or download the latest release from Pypi (https://pypi.python.org/pypi/progressbar2) or Github.

Note that the releases on Pypi are signed with my GPG key (https://pgp.mit.edu/pks/lookup?op=vindex&search=0xE81444E9CE1F695D) and can be checked using GPG:

gpg --verify progressbar2-<version>.tar.gz.asc progressbar2-<version>.tar.gz

Introduction

A text progress bar is typically used to display the progress of a long running operation, providing a visual cue that processing is underway.

The progressbar is based on the old Python progressbar package that was published on the now defunct Google Code. Since that project was completely abandoned by its developer and the developer did not respond to email, I decided to fork the package. This package is still backwards compatible with the original progressbar package so you can safely use it as a drop-in replacement for existing project.

The ProgressBar class manages the current progress, and the format of the line is given by a number of widgets. A widget is an object that may display differently depending on the state of the progress bar. There are many types of widgets:

The progressbar module is very easy to use, yet very powerful. It will also automatically enable features like auto-resizing when the system supports it.

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Known issues

  • The Jetbrains (PyCharm, etc) editors work out of the box, but for more advanced features such as the MultiBar support you will need to enable the "Enable terminal in output console" checkbox in the Run dialog.
  • The IDLE editor doesn't support these types of progress bars at all: https://bugs.python.org/issue23220
  • Jupyter notebooks buffer sys.stdout which can cause mixed output. This issue can be resolved easily using: import sys; sys.stdout.flush(). Linked issue: #173

Usage

There are many ways to use Python Progressbar, you can see a few basic examples here but there are many more in the examples file.

Wrapping an iterable

Progressbars with logging

Progressbars with logging require stderr redirection _before the StreamHandler is initialized. To make sure the stderr stream has been redirected on time make sure to call progressbar.streams.wrap_stderr() before you initialize the logger.

One option to force early initialization is by using the WRAP_STDERR environment variable, on Linux/Unix systems this can be done through:

If you need to flush manually while wrapping, you can do so using:

In most cases the following will work as well, as long as you initialize the StreamHandler after the wrapping has taken place.

Multiple (threaded) progressbars

Context wrapper

Combining progressbars with print output

Progressbar with unknown length

Bar with custom widgets

Bar with wide Chinese (or other multibyte) characters

Showing multiple independent progress bars in parallel


Naturally we can do this from separate threads as well:

About

Progressbar 2 - A progress bar for Python 2 and Python 3 - "pip install progressbar2"

http://progressbar-2.readthedocs.org/en/latest/

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 100.0%