Skip to main content

An annotated, single-line progress bar for terminals.

Project description

A simple way of providing an informative and clean progress bar on the terminal that knows a terminal’s current width, has a header, works out of the box when reading files, and always shows a relative percentage; progress_bar works for Python 2.6+ and 3.0+

Synopsis

file.txt: [========================79.3%===============>          ]

Installation

pip install progress_bar

Usage

Generally, to create any kind of progress bar with a default “size” of 100 arbitrary units:

from progress_bar import InitBar

pbar = InitBar()
pbar(10)  # update % to 10%
pbar(20)  # update % to 20%
pbar(15)  # simulate Microsoft progress effects

del pbar  # move bar to final 100% and write the newline

To easily create a progress bar for reporting (reading) progress in a filehandle that can tell() its offset:

from progress_bar import InitBarForInfile

pbar = InitBarForInfile("path/to/file.txt")
instream = open("path/to/file.txt")

for line in iter(instream.readline, ''):
  pbar(instream.tell())

del pbar

With those default arguments, the bar will be as wide as the terminal window. However, it will leave to characters space on both sides to achieve a visually more appealing display. Terminal window width is defined by termios using fcntl, both from the standard library. The progress bar will be prefixed with the basename of the input file (“file.txt” in the above example).

Version History

  • 6: removed remaining function annotations (Py2.7; thanks to Adam Knight)

  • 5: fixed a few rough edges from the last update

  • 4: made the bars with titles one-liners and fixed functions names (FunctionNames, ClassNames, methodNames, variable_names) because the PEP8 convention of using “snake_case” for nearly all names makes no sense to me what-so-ever… Finally, fixed the documentation to reflect Sphinx standards.

  • 3: fixed the version number so PEP426 issues are avoided (pip install now works…)

  • 2: updated the readme/usage section to reflect tell() issues with Python3

  • 1: initial release

Project details


Download files

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

Source Distribution

progress_bar-6.0.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file progress_bar-6.0.tar.gz.

File metadata

  • Download URL: progress_bar-6.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for progress_bar-6.0.tar.gz
Algorithm Hash digest
SHA256 a3107ec7d0976867f67a473323247d0d1e9fe4f306155d2c7746c18f5e4fcec8
MD5 48fe96e8d93c3f9269c027c5c373cd1e
BLAKE2b-256 bff7984662f6f054a5dab82c2f1dbcfea0ee0646810ec4c59fc44f4438efe52f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page