Stdlib-only measurement primitives — stopwatch, rate estimation, ETA prediction.
Project description
codechu-meter
___ _ _
/ __\___ __| | ___ ___| |__ _ _
/ / / _ \ / _\` |/ _ \/ __| '_ \| | | |
/ /__| (_) | (_| | __/ (__| | | | |_| |
\____/\___/ \__,_|\___|\___|_| |_|\__,_|
Stdlib-only measurement primitives — stopwatch, rolling-window rate
estimator, ETA predictor — extracted from the Disk Cleaner
toolchain. Depends only on
codechu-fmt for pretty
__str__ rendering. Python 3.10+.
Install
pip install codechu-meter
API
Stopwatch
from codechu_meter import Stopwatch
with Stopwatch() as sw:
do_work()
print(sw) # → '1m 30s' (via codechu-fmt)
print(sw.elapsed) # → float seconds
# Manual form
sw = Stopwatch().start()
do_work()
sw.stop()
RateEstimator
from codechu_meter import RateEstimator
re = RateEstimator(window_seconds=1.0)
for chunk in stream:
re.observe(len(chunk))
print(re.rate()) # float per-second
print(re) # → '1.2 MB/s' if unit='bytes'
Pass unit='items' (default), 'bytes', 'ops', or any custom
label — __str__ delegates to codechu_fmt.format_rate.
ETAEstimator
from codechu_meter import ETAEstimator
eta = ETAEstimator(total=1000, mode="ema")
for current in progress:
eta.update(current)
print(eta) # → '45s' or '?' if not enough samples yet
mode='linear' (default) uses overall throughput since
construction. mode='ema' blends an exponential moving average
of recent throughput for smoother numbers on bursty workloads.
eta() returns None until at least two updates with measurable
elapsed time and positive progress; __str__ renders that as '?'.
Design
- Stdlib + codechu-fmt only. No other dependencies.
- Monotonic clock. Wall-clock jumps don't break timing.
- Defensive. Zero progress, zero elapsed, NaN, and negative rates never raise.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codechu_meter-0.1.0.tar.gz.
File metadata
- Download URL: codechu_meter-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6cac73ae12d7f889ca58822198578f81afe22e805587c9bbe70580d1d5700cc
|
|
| MD5 |
d201849826513f50b97311d55becba82
|
|
| BLAKE2b-256 |
76a42498effc55170ce825c6032a2976e06216dff0ce0ce5653f676b9cd601c1
|
Provenance
The following attestation bundles were made for codechu_meter-0.1.0.tar.gz:
Publisher:
release.yml on codechu/meter-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codechu_meter-0.1.0.tar.gz -
Subject digest:
a6cac73ae12d7f889ca58822198578f81afe22e805587c9bbe70580d1d5700cc - Sigstore transparency entry: 1580190593
- Sigstore integration time:
-
Permalink:
codechu/meter-py@c8e8dfe51b29e0025b65685f1dc6577c3bce1524 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/codechu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c8e8dfe51b29e0025b65685f1dc6577c3bce1524 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file codechu_meter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: codechu_meter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebe17e66fac7b93395de0c0a15ebca66769128a120004dd1b480a540872ccae5
|
|
| MD5 |
a1a4c3d2df06928841ec167929b00d72
|
|
| BLAKE2b-256 |
f709e2c3fbdfc2e3e2a8c948588f70add9509b76061e63985e2c0eae8c2b580b
|
Provenance
The following attestation bundles were made for codechu_meter-0.1.0-py3-none-any.whl:
Publisher:
release.yml on codechu/meter-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codechu_meter-0.1.0-py3-none-any.whl -
Subject digest:
ebe17e66fac7b93395de0c0a15ebca66769128a120004dd1b480a540872ccae5 - Sigstore transparency entry: 1580190748
- Sigstore integration time:
-
Permalink:
codechu/meter-py@c8e8dfe51b29e0025b65685f1dc6577c3bce1524 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/codechu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c8e8dfe51b29e0025b65685f1dc6577c3bce1524 -
Trigger Event:
workflow_dispatch
-
Statement type: