Simple-Progress-Bar

A very simple copy-pasteable and customizable progress bar in Python, no import needed.

Look it on GitHub

Simple-Progress-Bar

Lire en Français.


Summary

What is it?

It is a progress bar you can use in any king of projects in Python, without installing anything.

Why should you use this one?

Because

What it looks like

The default progression bar looks like this

default bar

The Code

This is what you will have to copy-paste in your code

import sys

def progress_bar(count,total,size=100,sides="[]",full='#',empty='.',prefix=""):
    x = int(size*count/total)
    sys.stdout.write("\r" + prefix + sides[0] + full*x + empty*(size-x) + sides[1] + ' ' + str(count).rjust(len(str(total)),' ')+"/"+str(total))
    if count==total:
        sys.stdout.write("\n")

Usage

Here is an example of how you can use it

for i in range(1,101):
	progress_bar(count=i,total=100)
    time.sleep(0.01) # place you job here

Please note that, for better rendering, the last call should be done with count and total being equals.

What is customizable?

You can customize the prefix, the side characters, the done part and the remaining part characters and the width of the bar, for example

progress_bar(count=i,total=100,size=40,sides="||",full='█',empty=' ',prefix="working...")

gives the following bar

custom bar

What is not customizable?

A Unix-like dynamic prefix, colors and the i/n format advancement can’t be modified without changing the function’s code. Feel free to fork this project or create a pull request if you want to add those features.

Specifications

You can find those specifications in the function’s docstring in the source code

License

The project is a small one. The code is given to the GitHub Community for free, only under the MIT License, that is not too restrictive.