Progress Reporter
This library provides a simple interface to register different workloads and visualize their progress with either a plain text progress bar or a jupyter widget, depending on the current environment.
It optionally depends on Jupyter widgets to draw nice progress bars in the interactive Jupyter notebook environment.
Installation
with pip:
pip install progress_reporter
If you use IPython/Jupyter, you are strongly encourage to also install the jupyter widgets:
pip install ipywidgets
Examples
Image you have a class doing some heavy calculations, which are split into several jobs/tasks/threads etc.
In order to visualize the progress, one just needs to derive the worker class from progress_reporter.ProgressReporter and invoke the _progress_register method to tell the reporter how many pieces of work have to be done. Then the reporter is instructed by _progress_update(n) how many of pieces of work have been dispatched.
Note that these are “private” to use this class as a mixin class and not polute the public interface.
from progress_reporter import ProgressReporter
import time
class ExampleWorker(ProgressReporter):
def __init__(self, n_jobs=100):
self.n_jobs = n_jobs
""" register the amount of work with the given description """
self._progress_register(n_jobs, description='Dispatching jobs')
def work(self):
""" do some fake work (sleep) and update the progress via the reporter
"""
for job in (lambda: time.sleep(0.1) for _ in range(self.n_jobs)):
job()
# indicate we've finished one job, to update the progress bar
self._progress_update(1)
It also supports multi-stage sequential work loads by setting the parameter stage. This is just the dictionary key to the underlying process:
class MultiStageWorker(ProgressReporter):
def __init__(self, n_jobs_init, n_jobs):
self.n_jobs_init = n_jobs_init
self.n_jobs = n_jobs
""" register an expensive initialization routine """
self._progress_register(self.n_jobs_init, description='initializing', stage=0)
""" register the main computation """
self._progress_register(self.n_jobs, description='main computation', stage=1)
def work(self):
""" do the initialization """
for job in (lambda: time.sleep(0.1) for _ in range(self.n_jobs_init)):
job()
self._progress_update(1, stage=0)
""" perform the next stage of the algorithm """
for job in (lambda: time.sleep(0.2) for _ in range(self.n_jobs)):
job()
self._progress_update(1, stage=1)
Since version 2.0 there is also a version of the this class suitable for compositions.
from progress_reporter import ProgressReporter_
class Estimator(object):
def fit(self, X, y=None):
pg = ProgressReporter_()
pg.register(100, description='work')
with pg.context(): # ensure progress bars are closed if an exception occurs.
pg.update(50)
# ...
Metadata
Release files for progress-reporter 2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| progress-reporter-2.0.tar.gz | 49.0 kB | Without provenance | Details for progress-reporter-2.0.tar.gz |
Release files / progress-reporter-2.0.tar.gz
| Download URL | progress-reporter-2.0.tar.gz |
|---|---|
| Size | 49.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3268b3281f06894643073dae5205e41e2a3b3811b7a3c34e39ece8b4107e9a7b
|
|
BLAKE2b-256 checksum How to use checksums |
aa1fe2b16e98bc70a5a15d7df9ea2559d74ca037bf1c572387308111eaaad20b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Security for progress-reporter 2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.