Skip to main content

A single-threaded alternative to tqdm.

Project description

CircleCI Travis Appveyor Codecov Pypi Downloads ReadTheDocs

ProgIter

ProgIter lets you measure and print the progress of an iterative process. This can be done either via an iterable interface or using the manual API. Using the iterable inferface is most common.

ProgIter was originally developed independantly of tqdm, but the newer versions of this library have been designed to be compatible with tqdm-API. ProgIter is now a (mostly) drop-in alternative to tqdm. The tqdm library may be more appropriate in some cases. The main advantage of ``ProgIter`` is that it does not use any python threading, and therefore can be safer with code that makes heavy use of multiprocessing. The reason for this is that threading before forking may cause locks to be duplicated across processes, which may lead to deadlocks.

ProgIter is simpler than tqdm, which may be desirable for some applications. However, this also means ProgIter is not as extensible as tqdm. If you want a pretty bar or need something fancy, use tqdm; if you want useful information about your iteration by default, use progiter.

Package level documentation can be found at: https://progiter.readthedocs.io/en/latest/

Example

The basic usage of ProgIter is simple and intuitive. Just wrap a python iterable. The following example wraps a range iterable and prints reported progress to stdout as the iterable is consumed. The ProgIter object accepts various keyword arguments to modify the details of how progress is measured and reported. See API documentation of the ProgIter classs here: https://progiter.readthedocs.io/en/latest/progiter.progiter.html#progiter.progiter.ProgIter

Note that by default ProgIter reports information about iteration-rate, fraction-complete, estimated time remaining, time taken so far, and the current wall time.

>>> from progiter import ProgIter
>>> def is_prime(n):
...     return n >= 2 and not any(n % i == 0 for i in range(2, n))
>>> for n in ProgIter(range(1000), verbose=2):
>>>     # do some work
>>>     is_prime(n)
   0/1000... rate=0 Hz, eta=?, total=0:00:00, wall=12:47 EST
   1/1000... rate=58551.44 Hz, eta=0:00:00, total=0:00:00, wall=12:47 EST
 257/1000... rate=317349.77 Hz, eta=0:00:00, total=0:00:00, wall=12:47 EST
 642/1000... rate=191396.29 Hz, eta=0:00:00, total=0:00:00, wall=12:47 EST
1000/1000... rate=139756.95 Hz, eta=0:00:00, total=0:00:00, wall=12:47 EST

For more complex applications is may sometimes be desireable to manually use the ProgIter API. This is done as follows:

>>> from progiter import ProgIter
>>> n = 3
>>> prog = ProgIter(desc='manual', total=n, verbose=3)
>>> prog.begin() # Manually begin progress iteration
>>> for _ in range(n):
...     prog.step(inc=1)  # specify the number of steps to increment
>>> prog.end()  # Manually end progress iteration
manual 0/3... rate=0 Hz, eta=?, total=0:00:00, wall=12:46 EST
manual 1/3... rate=12036.01 Hz, eta=0:00:00, total=0:00:00, wall=12:46 EST
manual 2/3... rate=16510.10 Hz, eta=0:00:00, total=0:00:00, wall=12:46 EST
manual 3/3... rate=20067.43 Hz, eta=0:00:00, total=0:00:00, wall=12:46 EST

When working with ProgIter in either iterable or manual mode you can use the prog.ensure_newline method to guarantee that the next call you make to stdout will start on a new line. You can also use the prog.set_extra method to update a dynamci “extra” message that is shown in the formatted output. The following example demonstrates this.

>>> from progiter import ProgIter
>>> def is_prime(n):
...     return n >= 2 and not any(n % i == 0 for i in range(2, n))
>>> _iter = range(1000)
>>> prog = ProgIter(_iter, desc='check primes', verbose=2)
>>> for n in prog:
>>>     if n == 97:
>>>         print('!!! Special print at n=97 !!!')
>>>     if is_prime(n):
>>>         prog.set_extra('Biggest prime so far: {}'.format(n))
>>>         prog.ensure_newline()
check primes    0/1000... rate=0 Hz, eta=?, total=0:00:00, wall=12:55 EST
check primes    1/1000... rate=98376.78 Hz, eta=0:00:00, total=0:00:00, wall=12:55 EST
!!! Special print at n=97 !!!
check primes  257/1000...Biggest prime so far: 251 rate=308037.13 Hz, eta=0:00:00, total=0:00:00, wall=12:55 EST
check primes  642/1000...Biggest prime so far: 641 rate=185166.01 Hz, eta=0:00:00, total=0:00:00, wall=12:55 EST
check primes 1000/1000...Biggest prime so far: 997 rate=120063.72 Hz, eta=0:00:00, total=0:00:00, wall=12:55 EST

Installation

ProgIter can be easilly installed via pip.

pip install progiter

Alternatively, the ubelt library ships with its own version of ProgIter. Note that the ubelt version of progiter is distinct (i.e. ubelt actually contains a copy of this library), but the two libraries are generally kept in sync.

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

progiter-0.1.3.tar.gz (12.8 kB view details)

Uploaded Source

Built Distributions

progiter-0.1.3-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

progiter-0.1.3-py2-none-any.whl (16.9 kB view details)

Uploaded Python 2

File details

Details for the file progiter-0.1.3.tar.gz.

File metadata

  • Download URL: progiter-0.1.3.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.15

File hashes

Hashes for progiter-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a89f9ffc9b972b6fafc927c3752ac1329a12d4caad5c88895c3ba562cc6d17a1
MD5 146e43996189992de8f695317e10c38c
BLAKE2b-256 3f059f86604af0209e50ff4f2c4814b0614123249e17cc4f712b26db898897b8

See more details on using hashes here.

File details

Details for the file progiter-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: progiter-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.5.6

File hashes

Hashes for progiter-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8e21ec0531e689e4f7087c32806ac8cf682c20fb92346f612b78b2d8583ec5cc
MD5 b658e9448a848663af5a45810b7ba0e4
BLAKE2b-256 416e31d7e7e7c0ee2f458c438dbfe945d1786f8b5720a03bade5bb1be7c8ee1f

See more details on using hashes here.

File details

Details for the file progiter-0.1.3-py2-none-any.whl.

File metadata

  • Download URL: progiter-0.1.3-py2-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.15

File hashes

Hashes for progiter-0.1.3-py2-none-any.whl
Algorithm Hash digest
SHA256 da80f81372996e30d0fdeabd1ca8ccce29baf4be8d4a06ac2bede69fb99e96e0
MD5 cba748621c97accf1be8de1b8c9852b1
BLAKE2b-256 ad1c0c886ce6c281594f581b300fcd10d1fe710f6d1546fb63f18355580011f0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page