Skip to main content
Latest Published Version Build Status

report-on-interval

Print out regular status reports while looping over items

This package provides a function that simply prints out information about the progress of a loop that iterates over an iterable. So, say you have a 10k elements that you are iterating over and each one takes a second. Wouldn’t it be nice to get a little output after every 1% of the items are processed?

With report-on-interval, it’s as easy as this:

from report_on_interval import report_on_interval

for item in report_on_interval(lots_of_items):
    do_something_with_item(item)

Output would look like this:

processed 100 of 10000 items
processed 200 of 10000 items
processed 300 of 10000 items
processed 400 of 10000 items
...
processed 10000 of 10000 items

Super-quick Start

  • requirements: python versions 3.4+

  • install through pip: $ pip install report-on-interval

Additional Options

The report_on_interval function has some additional arguments that may be useful:

  • message

    Supply your own message for the report:

    for bug in report_on_interval(
            bug_generator,
            message='{i}/{n} little buggers squished',
    ):
        squash_bug(bug)
  • item_count

    If you are looping over an iterator that produces items programatically, you absolutely should provide this if you know the total number of items. Otherwise, report_on_interval will convert the iterable to a list, and, poof!, the benefits of programatically producing items disapears. A great example of this is iterating over the results from a SQLAlchemy query:

    query = session.query(MyModel).filter(MyModel.column > 0)
    for row in report_on_interval(
            query,
            item_count=query.count(),
    ):
        process_row(row)
  • printer

    Supply a different printer than the default of printing to standard out. This is often an application logger:

    from my_app.logging import logger
    for cheese in report_on_interval(cheese_shop, printer=logger):
        request_cheese(cheese)
  • get_deltas

    Provide your own method for computing the reporting interval. By default, the compute_reporting_interval method is used. This method prints after every 1% is processed for iterables with over 100k items, after every 10% for iterables over 30 items, and after every item for anything else

    def deltafier(n):
        return n // 7
    for marble in report_on_interval(bag, get_deltas=deltafier):
        shoot(marble)
  • report_at_end

    Print the progress report after the last item is processed. Maybe you want a report when your loop is done because you don’t report it yourself. There’s no accounting for tastes…

  • extra_actions

    Provide a list of additional tasks to perform on each reporting interval. One use for this is to regularly flush updates out to your database on the interval as well as reporting progress

    for new_thingie in report_on_interval(
        produce_new_thingies,
        item_count=thingie_total,
        extra_actions=[lambda: session.flush()],
    ):
        thingie.update(doodad=None)
  • extras_at_end

    Also perform the extra actions after finishing the loop. Note that like the report_at_end argument, if the count of items in the iterable is an exact multiple of the reporting interval, this will not result in an extra report and running the extras a second time. The logic in report_on_interval makes sure of that

Metadata

Release files for report-on-interval 0.1.0

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

Source distribution (sdist)

Source distribution for report-on-interval 0.1.0
File Size Uploaded
report-on-interval-0.1.0.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for report-on-interval 0.1.0
File Interpreter ABI Platform
report_on_interval-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.7 kB

Release files / report-on-interval-0.1.0.tar.gz

Download URL report-on-interval-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
32885e1dc7fef832e40a7d7410d4ca4b0639ec06e236a95bec7516596eb17130
BLAKE2b-256 checksum
How to use checksums
99cf9b5fcd9928e6242df5c0e3d324b22f6e9355ba749d8dfc8df67e9719e70a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / report_on_interval-0.1.0-py3-none-any.whl

Download URL report_on_interval-0.1.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc3a8a61b1714ef1feabd36f572004a37c12f1bb6a44c01ac228e3c195ccfb9f
BLAKE2b-256 checksum
How to use checksums
67e69cef8c8dacd2edc9e3f0c11bafb8c0db88f824ef65c5390d97450f45b232
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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