Skip to main content

Live-updating elapsed timer

Project description

LiveChrono

PyPI version

LiveChrono logo

LiveChrono is a lightweight, dependency-free Python package that shows a live updating stopwatch in the terminal, with pause/resume support and millisecond precision.

Demo of LiveChrono in action


Why LiveChrono?

Perfect for CLI scripts, quick profiling, demo timers, and any situation where a human-friendly live elapsed display is handy.

  • Tiny & dependency-free — single module, minimal surface area.
  • Human-friendly customizable outputHH:MM:SS.ms by default; fully customizable with format tokens.
  • Interruptible & accurate — pause/resume support; uses time.perf_counter() for elapsed measurement.

Installation

Install from PyPI:

pip install live-chrono

Features

  • Real-time terminal display on a single line that updates at a configurable interval.
  • Customizable format tokens (see below).
  • Pause/resume the chrono to measure the execution time of the desired methods.
  • Context-manager friendly (with LiveChrono()).
  • Returns a ChronoResult object with wall-clock timestamps and elapsed seconds.

Format Tokens

Token Meaning
%D days (unlimited)
%H hours (00-23)
%M minutes (00–59)
%S seconds (00–59)
%f milliseconds (000–999)
%ms alias for milliseconds

Note: Lower units roll over only if you include the higher unit.
Example: a format string with only %S may display 120 for two minutes.


Quickstart

Basic usage (context manager — recommended):

from live_chrono import LiveChrono
import time

with LiveChrono():
    time.sleep(0.35)

Pause/resume and capture the result with a custom output format:

from live_chrono import LiveChrono
import time

with LiveChrono(display_format="Elapsed: %S seconds and %f ms") as chrono:
    time.sleep(2.30)  # simulate work
    chrono.pause()    # temporary chrono pause  
    time.sleep(1)     # simulate non-relevant work for timer
    chrono.resume()   # resume the chrono  
    time.sleep(2.2)

# timer.result is available after the context exits
res = chrono.result
print(f"Elapsed seconds: {res.elapsed:.3f}")
# prints something like: Elapsed: 04 seconds and 500 ms

Manual start / pause / resume /stop:

from live_chrono import LiveChrono
import time

chrono = LiveChrono(update_interval=0.05)
chrono.start()
time.sleep(0.2)  # simulate work

chrono.pause()  # stop counting, display indicates paused
time.sleep(0.2)  # this work does NOT count for the chrono

chrono.resume()  # continue measuring the elapsed time
time.sleep(0.15)

result = chrono.stop()  # stops background thread, returns ChronoResult
print("Final:", result.elapsed)  # float seconds (e.g. 0.35)

API Reference

LiveChrono

LiveChrono(update_interval=0.1, display_format="Elapsed: %H:%M:%S.%f")

Create a live-updating timer.

Parameters

  • update_interval (float, default 0.1) – Refresh rate in seconds. Lower values update the display more frequently.
  • display_format (str, default "Elapsed: %H:%M:%S.%f") – Format string for rendering elapsed time (see format tokens above).

Methods

  • start() → LiveChrono – Begin timing and return the instance.
  • stop() → ChronoResult – Stop timing, join the background thread, and return a ChronoResult.
  • pause() – Pause the timer. No effect if already paused. Raises RuntimeError if called before start().
  • resume() – Resume from a paused state. No effect if not paused.
  • __enter__() / __exit__() – Context-manager support.

ChronoResult object

The ChronoResult model contains:

  • start_time: wall-clock start time (UNIX epoch seconds)
  • end_time: wall-clock end time (UNIX epoch seconds)
  • elapsed: elapsed time in seconds (float)
  • elapsed_format: elapsed time formated according the display_format
  • display_format: the format string used

Notes & Best Practices

  • The timer uses time.perf_counter() for high-resolution measurement of elapsed intervals, while time.time() is used for wall-clock start_time and end_time.
  • Small variations (a few ms) may appear due to thread scheduling or terminal printing.
  • Output is printed to stdout on a single line that refreshes each update.
  • The update_interval affects display smoothness only, not timing accuracy.
  • Multiple pause/resume cycles are supported, with elapsed time accumulating only while the timer is running.
  • For CLI usage, avoid extremely low update_interval values on slow terminals — printing overhead may affect readability.

License

This project is licensed under the MIT License.

You are free to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, provided that the copyright notice and permission notice appear in all copies.

See the LICENSE file for the full text.

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

live_chrono-1.0.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

live_chrono-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file live_chrono-1.0.0.tar.gz.

File metadata

  • Download URL: live_chrono-1.0.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for live_chrono-1.0.0.tar.gz
Algorithm Hash digest
SHA256 275930ccaf993ca696c2ade94ab59883418c61b92d88a87092e9f7e1374aca0d
MD5 91028c790009786b61d8206282b52207
BLAKE2b-256 7222002005170a93b6f22c891b708fd3f7b5699363f3c46fc0828323baaf974e

See more details on using hashes here.

File details

Details for the file live_chrono-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: live_chrono-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for live_chrono-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d859df445d5b37bcc0e148ca750df2d1f9184689ee50430cc0d36cc0937282e
MD5 d043faa4f7caa6ce5ca2a47e52f12b10
BLAKE2b-256 40553750196680b323ac3e19595ac09be40fc3d22e72a02fd552eb04122bb230

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