Python Status Bar

Written: 09/27/14

Last Updated: 01/07/15

I had the recent need to create a robust status bar in Python. I ended up getting a bit carried away and added a bunch of features to it. The status bar currently supports the following:

  1. In place updating
  2. Dynamic lengths (bar length as well as total screen length)
  3. Support for completeness greater than 100%
  4. Auto-scaling within the min and max bar lengths if completeness exceeds 999%
  5. Dynamic increment size
  6. Custom styling
  7. Compatible with Windows and *NIX

I have licensed the code under the MIT license, so feel free to use it for whatever purpose you may have.

You can grab the full source code, here. If you run the provided example (python, it will show you how to use all of the features. The code is heavily commented, so you should be able to follow it, if not please ask for clarification. For those of you that only care about how the status bar can be updated inline, look at lines 162 – 166. All that is required is to write to stdout directly and use the carriage return character, ‘\r’, to reset to the beginning of the line. After that, the rest is up to you, as to how you wish to display the information.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.