Skip to main content

Simplify printing loops progress

Project description

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.

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

looprint-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

looprint-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file looprint-0.1.0.tar.gz.

File metadata

  • Download URL: looprint-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for looprint-0.1.0.tar.gz
Algorithm Hash digest
SHA256 68d34e8ac81118f46b0be862559d3ca46592e350549b86be2c0273c797631615
MD5 6130addb3ef995a789b9f9ba2d5857bd
BLAKE2b-256 5d39555287dc8c7dc2b471130f1d7b0765d57caa185a3accee3047a08f161329

See more details on using hashes here.

File details

Details for the file looprint-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: looprint-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for looprint-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db1f73032081de47aff72466bb849ea79ffc38b7f7d72b9804d91da959b0eafb
MD5 75e5e5b5e921b50d1655d29c715265d0
BLAKE2b-256 d8f8fe8d87ca90f241200bdc2357201cb154ab60ea08272cddb949891c778b79

See more details on using hashes here.

Supported by

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