Skip to main content

A Python module that creates horizontal progress bars to keep track of the progress of threaded jobs. Progress Bars in this module are totally customizable

Project description

Htpbs

Htpbs is a Python library that creates horizontal progress bars to keep track of the progress of threaded jobs. Bars in htpbs are completely customizable.

Installation

Use the package manager pip to install htpbs.

pip install htpbs

Usage

The following are examples about how to use this library for threaded and non threaded bars

Threaded horizontal bars

from htpbs import ProgressBars, Work
import time # required for demonstration purposes only


# Note: users can create any configuration or function to be passed to the Work object below.
def work(progressbars, bar_index, work_value, work_name):
    """

    :param progressbars: the progressbar obkect
    :param bar_index: a integer representing the index of the bae
    :param work_value: a value for time.sleep() to simulate different progress bars rates
    :param work_name: the name of the work
    :return: VOID
    """
    progressbars.set_bar_prefix(bar_index=bar_index, prefix=work_name)
    for i in range(101):
             # your work here. we use the time.sleep() as example
             # Real work could be downloading a file and show progress
             time.sleep(work_value)
             progressbars.update(bar_index=bar_index, value=i)
    progressbars.finish()

# start with 3 bars
progressbars = ProgressBars(num_bars=3)
# set bar #3 to be the total progress
progressbars.set_last_bar_as_total_progress(prefix="Total: ")

# start all the threaded works
Work.start(work, (progressbars, 0, 0.1, "w1: "))
Work.start(work, (progressbars, 1, 0.01, "w2: "))

# output after works finished
# w1: |██████████| 100% completed   w2: |██████████| 100% completed    Total: |██████████| 100% completed

Using the same thread

from htpbs import ProgressBars
import time # required for demostration purposes only

progressbars = ProgressBars(num_bars=5)
progressbars.set_last_bar_as_total_progress(prefix="Total Progress: ")

# set total progress bar at any index 
# progressbars.set_total_bar(index=3, prefix="total: ")

# using the same thread 
for i in range(101):
    time.sleep(0.1)
    values = [i, i+5, i+10, i+15, 0] # zero for init total progress 
    progressbars.update_all(values) # update bars in the same thread
progressbars.finish_all() # avoid memory leaks. 

Remove bars when job is done and init the next bar

# clearing and initializing new progress bars:
from htpbs import ProgressBars
import time # required for demostration purposes only

progressbars = ProgressBars(num_bars=3)
progressbars.set_last_bar_as_total_progress(prefix="Total Progress: ")

# hide the bars that are not being used at the moment
# multiple bars can be hidden at the same time
progressbars.set_hidden_bars([1]) 

# non threaded work 1 starts
for i in range(101):
    time.sleep(0.1)
    progressbars.update(bar_index=0, value=i)
progressbars.finish()

# clears the bar that was completed from screen
progressbars.clear_bar(bar_index=0) 
# resets the new bar that will appear in screen
progressbars.reset_bar(index=1, prefix="new bar: ")   

# non threaded work 2 starts
for i in range(101):
    time.sleep(0.1)
    progressbars.update(bar_index=1, value=i)
progressbars.finish()

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

htpbs

version: 0.0.4

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

htpbs-0.0.4.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

htpbs-0.0.4-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file htpbs-0.0.4.tar.gz.

File metadata

  • Download URL: htpbs-0.0.4.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

File hashes

Hashes for htpbs-0.0.4.tar.gz
Algorithm Hash digest
SHA256 4e1cc4bc66ea5f21cd1a2b21a9725e026794d016fb047f0368f1b72eca5f6549
MD5 9360770144a2b9f1fd32dfd619afef92
BLAKE2b-256 8d7da3308b492eafaefef24375884c9cf765a44fc7617d0af1d6bc59dd1d7279

See more details on using hashes here.

File details

Details for the file htpbs-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: htpbs-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

File hashes

Hashes for htpbs-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 644fb3ebf5a93e857758e5371d2415e3b32a5e4222b74f769b75bcafb6ad24af
MD5 b4cb6951f7675c8c48636b23b45b4ae7
BLAKE2b-256 59a0dae0d58faef40a7d47696d521175e5491f08da369a834e5efa62fe8864b6

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