Skip to main content

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

  • always shows a relative percentage

  • 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 a Microsoft progress bar
pbar(100) # done

del pbar  # 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("./README.rst")
instream = open("./README.rst")

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 have two whitespaces on both sides of the bar 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

  • 8: README improvements thanks to Marc Abramowitz, @msabramo

  • 7: fixed error with InitBar when no title is given

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

  • 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

Release files for progress_bar 8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for progress_bar 8
File Size Uploaded
progress_bar-8.tar.gz 5.2 kB Details

Release files / progress_bar-8.tar.gz

Download URL progress_bar-8.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
befbbcc07fbce96c7b2bed17fffd2203d0269d94ade502b6e003652ba0050efd
BLAKE2b-256 checksum
How to use checksums
b4fbd45c6a34e1242f4c7abef5f98aeb29e7096518defcf390bd601b5d3148ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

8 This release

1 release file

7

1 release file

6.0

1 release file

5.0

1 release file

4.0

1 release file

3.0.0

1 release file

2

1 release file

1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page