Skip to main content

A library for tracking, computing, and formatting time estimates.

Project description

ETA Time

A library for tracking, computing, and formatting time estimates.

Basic Usage

import time, random
from etatime.eta import eta_calculator


# Just a placeholder function that takes a random amount of time
def process_item(item):
    time.sleep(random.random() * 20)


for item, eta in eta_calculator(range(10)):  # Creates a new Eta object for each item
    print(eta)  # Print the current progress stats
    process_item(item)  # Do your processing here

If you want to access the eta stats outside the loop, you can use this pattern to do so:

eta = None  # Initialize the eta variable here, so we can use it outside the loop
for item, eta in eta_calculator(range(10)):
    print(eta)
    process_item(item)
eta.complete()  # Update the last Eta object to completed, using now as the end time

print(f"Done processing {eta.total_items} items in {eta.string(eta.StringField.TIME_TAKEN)}!\n")

Here is an example of the sort of output this produces:

0.00%
10.00% | R: 0:01:33 | E: 12:25:16 AM
20.00% | R: 0:01:56 | E: 12:25:57 AM
30.00% | R: 0:01:13 | E: 12:25:16 AM
40.00% | R: 0:00:55 | E: 12:25:03 AM
50.00% | R: 0:00:55 | E: 12:25:22 AM
60.00% | R: 0:00:43 | E: 12:25:18 AM
70.00% | R: 0:00:32 | E: 12:25:19 AM
80.00% | R: 0:00:19 | E: 12:25:09 AM
90.00% | R: 0:00:09 | E: 12:25:00 AM
Done processing 10 items in 0:01:33!

You can get more verbose information by replacing the for loop with this:

for item, eta in eta_calculator(range(10), verbose=True):

Here is an example of the verbose output:

0.00% (0/10)
10.00% (1/10) | Time remaining: 1 minute and 54 seconds | ETA: 12:27:33 AM US Mountain Standard Time
20.00% (2/10) | Time remaining: 1 minute and 33 seconds | ETA: 12:27:22 AM US Mountain Standard Time
30.00% (3/10) | Time remaining: 1 minute and 7 seconds | ETA: 12:27:02 AM US Mountain Standard Time
40.00% (4/10) | Time remaining: 50 seconds | ETA: 12:26:49 AM US Mountain Standard Time
50.00% (5/10) | Time remaining: 51 seconds | ETA: 12:27:08 AM US Mountain Standard Time
60.00% (6/10) | Time remaining: 41 seconds | ETA: 12:27:09 AM US Mountain Standard Time
70.00% (7/10) | Time remaining: 28 seconds | ETA: 12:27:01 AM US Mountain Standard Time
80.00% (8/10) | Time remaining: 20 seconds | ETA: 12:27:05 AM US Mountain Standard Time
90.00% (9/10) | Time remaining: 10 seconds | ETA: 12:27:07 AM US Mountain Standard Time
Done processing 10 items in 1 minute and 51 seconds!

You can also build a custom message piece-by-piece, like so:

print(f"Processing item: '{item}'")
print(f"  Completed: {eta.string(eta.Value.COMPLETION)}")
print(f"  Time taken: {eta.string(eta.Value.TIME_TAKEN)}")
print(f"  Time remaining: {eta.string(eta.Value.TIME_REMAINING)}")
print(f"  ETA: {eta.string(eta.Value.ETA)}")

This produces the following output:

Processing item: '0'
  Completed: 0.00% (0/10)
  Time taken: 0 seconds
  Time remaining: not enough data
  ETA: not enough data
Processing item: '1'
  Completed: 10.00% (1/10)
  Time taken: 11 seconds
  Time remaining: 1 minute and 38 seconds
  ETA: 12:29:31 AM US Mountain Standard Time
Processing item: '2'
  Completed: 20.00% (2/10)
  Time taken: 29 seconds
  Time remaining: 1 minute and 55 seconds
  ETA: 12:30:05 AM US Mountain Standard Time
Processing item: '3'
  Completed: 30.00% (3/10)
  Time taken: 47 seconds
  Time remaining: 1 minute and 50 seconds
  ETA: 12:30:18 AM US Mountain Standard Time
Processing item: '4'
  Completed: 40.00% (4/10)
  Time taken: 54 seconds
  Time remaining: 1 minute and 21 seconds
  ETA: 12:29:57 AM US Mountain Standard Time
Processing item: '5'
  Completed: 50.00% (5/10)
  Time taken: 56 seconds
  Time remaining: 56 seconds
  ETA: 12:29:33 AM US Mountain Standard Time
Processing item: '6'
  Completed: 60.00% (6/10)
  Time taken: 1 minute and 3 seconds
  Time remaining: 42 seconds
  ETA: 12:29:27 AM US Mountain Standard Time
Processing item: '7'
  Completed: 70.00% (7/10)
  Time taken: 1 minute and 22 seconds
  Time remaining: 35 seconds
  ETA: 12:29:38 AM US Mountain Standard Time
Processing item: '8'
  Completed: 80.00% (8/10)
  Time taken: 1 minute and 28 seconds
  Time remaining: 22 seconds
  ETA: 12:29:32 AM US Mountain Standard Time
Processing item: '9'
  Completed: 90.00% (9/10)
  Time taken: 1 minute and 48 seconds
  Time remaining: 12 seconds
  ETA: 12:29:41 AM US Mountain Standard Time
Done processing 10 items in 1 minute and 57 seconds!

Full Documentation

etautil on Read the Docs

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

etatime-2.7.1.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

etatime-2.7.1-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file etatime-2.7.1.tar.gz.

File metadata

  • Download URL: etatime-2.7.1.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for etatime-2.7.1.tar.gz
Algorithm Hash digest
SHA256 a49f3334e88e7f064579c2a7fa06c4621e92184af30c86f9dd6d4c4aa60d0912
MD5 75bbe0594ed5f8fcb1dcad2c108c4ef0
BLAKE2b-256 515ce8e374ba17c18fe451c46f1226b8ddbfcb307d11f961037bbea8f6f2eb55

See more details on using hashes here.

File details

Details for the file etatime-2.7.1-py3-none-any.whl.

File metadata

  • Download URL: etatime-2.7.1-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for etatime-2.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1fa2ce04d6555fc611a5728a7504fef85ae7d999c85634c241e5918ee61fc512
MD5 4e9902da946d3aab1938571cbe6d3f4b
BLAKE2b-256 d14ff95bd964a1fe8ca88bf578115a3fd5c6340320a66dd5843146beff034e0a

See more details on using hashes here.

Supported by

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