Skip to main content

Stdlib-only measurement primitives — stopwatch, rate estimation, ETA prediction.

Project description

        .--:--.          c o d e c h u
       /  12   \           ╔═════════╗
      |9   ●---3|  meter   ║ 00:42.7 ║   ETA  03:18
       \   6   /           ╚═════════╝
        '-----'          ─── tick · tock · tick · tock ───

Stopwatch, rolling-rate, and ETA — time things without lying about them.

codechu-meter

Stdlib-only measurement primitives — stopwatch, rolling-window rate estimator, ETA predictor — extracted from the Disk Cleaner toolchain. Zero dependencies. Python 3.10+.

Install

pip install codechu-meter

API

Stopwatch

from codechu_meter import Stopwatch

with Stopwatch() as sw:
    do_work()
print(sw.elapsed)  # → float seconds

# Manual form
sw = Stopwatch().start()
do_work()
sw.stop()
print(sw.elapsed)

Formatting is up to you. If you want pretty output, pair with codechu-fmt:

from codechu_fmt import format_duration
print(format_duration(sw.elapsed))  # → '1m 30s'

RateEstimator

from codechu_meter import RateEstimator

re = RateEstimator(window_seconds=1.0, unit="bytes")
for chunk in stream:
    re.observe(len(chunk))
print(re.rate())   # float per-second

unit is just an attribute — it never affects the numeric rate(). Use it as a label when formatting:

from codechu_fmt import format_rate
print(format_rate(re.rate(), unit=re.unit))  # → '1.2 MB/s'

ETAEstimator

from codechu_meter import ETAEstimator

eta = ETAEstimator(total=1000, mode="ema", alpha=0.3)
for current in progress:
    eta.update(current)
    remaining = eta.eta()  # float seconds or None

mode='linear' (default) uses overall throughput since construction. mode='ema' blends an exponential moving average of recent throughput for smoother numbers on bursty workloads. The alpha parameter (default 0.3) controls EMA reactivity: higher values weight recent samples more heavily.

eta() returns None until at least two updates with measurable elapsed time and positive progress.

Design

  • Zero dependencies. Stdlib only.
  • Monotonic clock. Wall-clock jumps don't break timing.
  • No formatting coupling. Numeric primitives only; pair with codechu-fmt (or roll your own) for display strings.
  • Defensive. Zero progress, zero elapsed, NaN, and negative rates never raise.

Migrating from 0.1.x

__str__ methods were removed in 0.2.0. Replace print(sw) / str(re) / str(eta) with explicit calls:

# Before (0.1.x)
print(sw)
print(re)
print(eta)

# After (0.2.x)
from codechu_fmt import format_duration, format_rate
print(format_duration(sw.elapsed))
print(format_rate(re.rate(), unit=re.unit))
v = eta.eta()
print(format_duration(v) if v is not None else "?")

Tests

pip install -e ".[dev]"
pytest -q

Coverage gate: ≥90 %. Tests drive time via monkeypatching time.monotonic for deterministic assertions.

License

MIT — see LICENSE.

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

codechu_meter-0.2.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

codechu_meter-0.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file codechu_meter-0.2.0.tar.gz.

File metadata

  • Download URL: codechu_meter-0.2.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codechu_meter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 38119b5ece9b288b8bdc2c0b7e01b07d57c6909b1ab2f5755503ae4d654c83cf
MD5 883132fc2b507ad104ba097841b1c7b1
BLAKE2b-256 fe01fbd64bd4fd039c8a6caddbc4af814909d7c861b36a322dba53356106fbf9

See more details on using hashes here.

Provenance

The following attestation bundles were made for codechu_meter-0.2.0.tar.gz:

Publisher: release.yml on codechu/meter-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codechu_meter-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: codechu_meter-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codechu_meter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1dfa614949c13ea964939976713737ccb7929bb12502df6b0d27d6d8537e3816
MD5 5d168523275caab08f63af73b9cb530f
BLAKE2b-256 879076c7003823446ad7f7ff2c3f022aba70a5bb17aefa04d974d378aa14a9b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for codechu_meter-0.2.0-py3-none-any.whl:

Publisher: release.yml on codechu/meter-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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