Skip to main content

frogress - progress tool for snakes

Build Status

Coverage Status

                /----------------------------------------------------------------------------------\
                |                                                                                  |
      @..@     /| [###.......] Progress: 34.2MB / 125.8MB |  25.0% | Time: 14min3s | ETA: 19min52s |
     (----)   / |                                                                                  |
    ( >__< )    \----------------------------------------------------------------------------------/
    ^^ ~~ ^^

frogress is small progress indication tool to be used for fast prototyping. Why frogress anyway? Because it's a bar (most of the time) and it jumps on your terminal, that's why!

  • Does NOT break your workflow (in most cases there is no need to call progress bar to render itself)
  • It can guess if you iterate over a list (or similar iterable) ...
  • or if iterate over a file ...
  • or if iterate over generator - provided you know it's total length ...
  • or not! (no eta, no total steps, no percentage and indicator instead of a bar but it works!)
  • And you can easily teach it how to show progress of fat, gzipped xml file when using lxml to parse it
  • Supports Python 2.6+, Python 3, PyPY
  • Fully tested

Iteration examples

Iterate over a list


    >>> import frogress
    >>> items = [1, 2, 3, 4, 5]
    >>> for item in frogress.bar(items):
    ...     pass # do something with item

    [##........] Step 2/5 |  20.0% | Time: 0.1s | ETA: 0.5s

Iterate over a file


    >>> import frogress
    >>> for line in frogress.bar(open('/path/to/file', steps_label='Progress')):
    ...     pass # do something cruel with a line

    [###.......] Progress: 3.2MB / 12.8MB |  25.0% | Time: 14min3s | ETA: 19min52s

Iterate over generator


    >>> import frogress
    >>> count = 100
    >>> items = range(count)
    >>> for item in frogress.bar(items, steps=count):
    ...     pass # do something with item

    [#########.] Step 86/100 |  86.0% | Time: 1.2s | ETA: 7.3s

Iterate over a generator with unknown total number of steps


    >>> import frogress
    >>> def counter():
    ...     num = 1
    ...     while True:
    ...         yield num
    ...         num += 1
    ...
    >>> items = counter()
    >>> for item in frogress.bar(items):
    ...     pass # do something with item

    [........#.] Step: 1410 | Time: 2min14s
    [.........#] Step: 1411 | Time: 2min15s
    [........#.] Step: 1412 | Time: 2min16s
    [.......#..] Step: 1413 | Time: 2min17s

Iterate over gzipped xml file using lxml

The only problem with how to present a progress of file that's being processed is the source from which frogress should extract progress information. We can try to do this simple way (without knowledge of how much of the file is already processed) or give frogress a source.

Simple way


    >>> import frogress
    >>> import gzip
    >>> from lxml.etree import iterparse
    >>> stream = gzip.open('my-fat.xml.gz')
    >>> context = iterparse(stream)
    >>> for action, element in frogress.bar(context):
    ...     pass # do something with element
    ...     element.clear() # don't forget about the memory!

    [...#......] Progress: 41923 | Time: 1h42min

This is perfectly fine: we passed an iterable that doesn't provide information on how many total items there is to process - so we have an bar activity indicator, no total steps at the progress and no ETA.

However, there is clearly a way of retrieving this information - after all this is only a file that's being processed. And that file should be passed as source argument to the frogress.bar function.

Pass source


    >>> import frogress
    >>> import gzip
    >>> from lxml.etree import iterparse
    >>> stream = gzip.open('my-fat.xml.gz')
    >>> context = iterparse(stream)
    >>> for action, element in frogress.bar(context, source=stream.myfileobj):
    ...     pass # do something with element
    ...     element.clear() # don't forget about the memory!

    [#####.....] Progress: 73.5MB / 156.4MB |  47.3% | Time: 1h42min | ETA: 1h53min

Just remember to pass file that is actually processed, not a wrapper! Standard file would be passed directly, however in example, gzip module wraps stream it is working on and it's available as attribute myfileobj. On the other hand bz2 module doesn't wrap streams. And so on. frogress can guess if a stream is file like object, however passing proper source is responsibility of the user.

Spinner without actual iterable

Sometimes we just want to show that program is doing something but we don't really know how long it would take (i.e. perform couple of API requests).

Example

import frogress
import time

def cmd(s=0):
    time.sleep(s)


def main():
    with frogress.spinner("Waiting for response 1", done="OK"):
        cmd(0.5)
    with frogress.spinner("Waiting for response 2", done="Done"):
        cmd(0.5)
    with frogress.spinner("Waiting for response 3", done="All done, really!"):
        cmd(0.5)

main()

demo-multi-commands-simple

Progress bar class API

Most of the time you won't need to call those API directly - frogress.bar function should work for majority of the use cases. If, however, you feel like you need to make some customization, here we present some examples


    >>> import frogress
    >>> items = [1, 2, 3, 4, 5]
    >>> progressbar = frogress.Bar(items)
    >>> progressbar.step
    0
    >>> progressbar.started # it's still None
    >>> progressbar.finished # here too
    >>> for item in progressbar:
    ...     pass # process the item (it will draw progressbar during iteration)
    >>> progressbar.step
    5
    >>> progressbar.widgets
    [<BarWidget>, <ProgressWidget>, <PercentageWidget>, <EtaWidget>, <TimeWidget>]
    >>> len(progressbar)
    5
    >>> progressbar.output
    <open file '<stderr>', mode 'w' at 0x103df61e0>
    >>> progressbar.started
    datetime.datetime(2013, 5, 12, 22, 2, 26, 752454)
    >>> progressbar.finished
    datetime.datetime(2013, 5, 12, 22, 2, 26, 792901)

Tips & Tricks

How to change label of the progress widget


    >>> import frogress
    >>> items = [1, 2, 3, 4, 5]
    >>> widgets = [frogress.BarWidget, frogress.ProgressWidget('Items: '), frogress.TimerWidget]
    >>> for item in frogress.bar(items, widgets=widgets):
    >>>     pass


Metadata

Release files for frogress 0.10.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for frogress 0.10.1
File Size Uploaded Provenance
frogress-0.10.1.tar.gz 19.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for frogress 0.10.1
File Interpreter ABI Platform
frogress-0.10.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.5 kB

Release files / frogress-0.10.1.tar.gz

Download URL frogress-0.10.1.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0150cfb988eeda65e019283a06b69603c26457081c545b1b143d907996bf96d3
BLAKE2b-256 checksum
How to use checksums
6d5035f9d1758ac852fe75cd5d687709710ea076fad9b5fdb9f2f6d53f5510d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / frogress-0.10.1-py3-none-any.whl

Download URL frogress-0.10.1-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a47be1dbca0b89dcbd0628063a159948ff96343e4f5086a4f25e2780469f96d7
BLAKE2b-256 checksum
How to use checksums
bae44e7f4f4148854d63550c96acfb5daec82aec5f801f07323822ab84ae5910
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Security for frogress 0.10.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page