Skip to main content

looprint

looprint is a Python utility designed to enhance the visibility of loops by providing real-time progress updates in the console. It works seamlessly with any iterable and updates the console output to reflect the current state of processing, making it especially useful for long-running tasks.

Features

  • Real-time updates: Displays progress information in the console while iterating over an iterable.
  • Elapsed and remaining time: Provides estimates for how long the iteration has been running and how much time is left until completion.
  • Customizable loop name: Allows you to specify a name for the loop for better context in your logs.
  • Compatibility: Works with any iterable, including lists, dictionaries, sets, etc.

Installation

pip install looprint

No additional installation is required.

Usage

To use looprint, import it into your script and then iterate over any iterable by passing it as loopprint argument. Here’s a simple example demonstrating its functionality:

from looprint import looprint

# Example data
#-----------------------------------
myList = ['value1', 'value2', 'value3']
myDict = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
#-----------------------------------

# Example loops with processing logs
#-----------------------------------
for value in looprint(myList):
  print(value)  # Your processing logic
  # ...

for key, value in looprint(data.items()):
    print(key, ':', value)  # Your processing logic
    # ...
#-----------------------------------

Parameters

  • data (Iterable): The iterable you want to process (e.g., list, dict, set).
  • loopName (str): Optional. A name for the loop that will be displayed in the progress messages (default is "Loop").

How it works

  1. When you start the loop, looprint will print an initial message indicating the beginning of processing.

  2. For each item in the iterable, it will update the console with the current progress, including:

  • The number of items processed so far.
  • The total number of items.
  • The percentage of completion.
  • The elapsed time and the estimated remaining time.
  1. After processing all items, it will print a summary of the total items processed and the total time taken.

Example Output

When using the looprint class with the above examples, the console will show updates like this:

---------- Loop
value1
value2
----------
Processing Loop... 2 of 3 (66.66%) | Elapsed: 4.0000 sec - Remaining: 2.0000 sec
----------
---------- Loop
key1 : value1
key2 : value2
----------
Processing Loop... 2 of 3 (66.66%) | Elapsed: 4.0000 sec - Remaining: 2.0000 sec
----------

Notes

  • Make sure that the output device (e.g., terminal or console) supports ANSI escape codes for proper formatting.
  • Use time.sleep() or similar calls in your processing to see the progress updates in action.

License

This project is open-source and available under the MIT License. Feel free to use, modify, and distribute it as needed.

Release files for looprint 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 looprint 0.1.0
File Size Uploaded
looprint-0.1.0.tar.gz 4.0 kB Details

Built distribution (wheel)

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

Total release size: 8.3 kB

Release files / looprint-0.1.0.tar.gz

Download URL looprint-0.1.0.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
68d34e8ac81118f46b0be862559d3ca46592e350549b86be2c0273c797631615
BLAKE2b-256 checksum
How to use checksums
5d39555287dc8c7dc2b471130f1d7b0765d57caa185a3accee3047a08f161329
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

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

Download URL looprint-0.1.0-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db1f73032081de47aff72466bb849ea79ffc38b7f7d72b9804d91da959b0eafb
BLAKE2b-256 checksum
How to use checksums
d8f8fe8d87ca90f241200bdc2357201cb154ab60ea08272cddb949891c778b79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

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