Skip to main content

A simple python package to create Progress bars as Strings

Project description

project-image

shields

🚀 Usage

ProgressBar has quite a few parameters:

Parameter name Mandatory Type Description
value yes int Current value of the progress bar
total yes int Max value of the progress bar
string_length yes int Length of the bar
unfilled_char no str char that displays the unfilled portion of the bar. Defaults to "▬".
progress_char no str char that displays the filled portion of the bar. Defaults to "🔘".
fill_bar no bool If the left side of the bar should also be filled. Defaults to False.

Examples:

from strprogressbar import ProgressBar
# create a progressbar with a width of 25 characters
# we are in step 67/85
p = ProgressBar(67, 85, 25)
print(p)

>>> "▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬🔘▬▬▬▬▬"
from strprogressbar import ProgressBar
# create a progressbar with a width of 20 characters
# we are in step 3/5, change the default characters
# fill in the progress that we already made
p = ProgressBar(3, 5, 20, "░", "▓", True)
print(p)

>>> "▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░"
from strprogressbar import ProgressBar
# create a progressbar with a width of 30 characters
# we are in step 8/15, change the default characters
# fill in the progress that we already made with 2 chars
p = ProgressBar(8, 15, 30, "░", "▒▓", True)
print(p)

>>> "▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓░░░░░░░░░░░░░░"

What if we want to show our progress in numbers or in percentage?

ProgressBar has 4 default functions to add or remove this feature.

Note that adding percentage or counter does not alter the size of the progress bar. eg: If you set string_length to 20 and added a percentage indicator, the progress bar will still be 20 chars long, but the total string will be longer with the percentage sign.

add_percentage()

Parameters

Parameter name Mandatory Type Description
decimals no int The amount of decimals to display. Defaults to 0.
left no bool If the percentage should be displayed to the left of the progress bar. Defaults to False/right side.
seperator no str The seperator between the progress bar and the percentage number. Defaults to " ".

Example

from strprogressbar import ProgressBar
# create a progressbar with a width of 25 characters
# we are in step 30/64 and display this on the right side with 2 decimals
p = ProgressBar(30, 64, 25).add_percentage(2, False)
print(p)

>>> "▬▬▬▬▬▬▬▬▬▬▬🔘▬▬▬▬▬▬▬▬▬▬▬▬▬ 46.88%"
    |__________________________|
            25 characters

remove_percentage()

Parameters

This function has no parameters.

Example

from strprogressbar import ProgressBar
# create a progressbar with a width of 25 characters
# we are in step 30/64 and display this on the right side with 0 decimals
p = ProgressBar(30, 64, 25).add_percentage(0, False, ' @ ')
print(p)
# remove the percentage
print(p.remove_percentage())

>>> "▬▬▬▬▬▬▬▬▬▬▬🔘▬▬▬▬▬▬▬▬▬▬▬▬▬ @ 47%"
>>> "▬▬▬▬▬▬▬▬▬▬▬🔘▬▬▬▬▬▬▬▬▬▬▬▬▬"

add_counter()

Parameters

Parameter name Mandatory Type Description
left no bool If the percentage should be displayed to the left of the progress bar. Defaults to False/right side.
seperator no str The seperator between the progress bar and the percentage number. Defaults to " "

Example

from strprogressbar import ProgressBar
# create a progressbar with a width of 25 characters
# we are in step 67/85 and display this on the left side
p = ProgressBar(67, 85, 25).add_counter(True, " - ")
print(p)

>>> "67/85 - ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬🔘▬▬▬▬▬"

We can also add both a counter and a percentage indicator:

from strprogressbar import ProgressBar
# create a progressbar with a width of 25 characters
# we are in step 67/85 and display this on the left side
# add a percentage indicator on the right side
p = ProgressBar(67, 85, 25).add_counter(True, " - ").add_percentage(1, False, " - ")
print(p)

>>> "67/85 - ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬🔘▬▬▬▬▬ - 78.8%"

remove_counter()

Parameters

This function has no parameters.

Example

from strprogressbar import ProgressBar
# create a progressbar with a width of 25 characters
# we are in step 18/64 and display this on the right side with 0 decimals
p = ProgressBar(18, 64, 25, "░", "▓", True).add_counter(False).add_percentage()
print(p)
# remove the percentage
print(p.remove_counter())

>>> "▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░ 28% 18/64"

>>> "▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░ 28%"

🛠️ Installation Steps:

1. Installing

pip install strprogressbar

🛡️ License:

This project is licensed under the GNU General Public License v3.0

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

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

Source Distribution

strprogressbar-1.0.tar.gz (17.0 kB view details)

Uploaded Source

File details

Details for the file strprogressbar-1.0.tar.gz.

File metadata

  • Download URL: strprogressbar-1.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for strprogressbar-1.0.tar.gz
Algorithm Hash digest
SHA256 7d5b481175aaaf97bdf4f17318368c299faea23ceb0fb3c2f4ecf6d760243d57
MD5 ffeef3f14f31a9646c819813770c0b72
BLAKE2b-256 70a05e5b0b81cdaa379fafcf93764059941a71079095dbd1a709cfc21a7af51e

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