TimeRun — Structured timing for Python.
TimeRun is a single-file Python package with no dependencies beyond the standard library. It records wall-clock time and CPU time when you measure a block or function calls (one Measurement per block or per call) and supports optional metadata (e.g. run id, tags) and callbacks (on_start / on_end) per measurement.
For positioning and the full value proposition, see Overview on the docs site.
Installation
From PyPI:
pip install timerun
From source:
pip install git+https://github.com/HH-MWB/timerun.git
Note: Requires Python 3.10+.
Usage
Time Code Block
Use with Timer() as m: (or async with). The yielded Measurement has wall_time and cpu_time:
>>> from timerun import Timer
>>> with Timer() as m:
... pass # code block to be measured
...
>>> m.wall_time.timedelta
datetime.timedelta(microseconds=11)
>>> m.cpu_time.timedelta
datetime.timedelta(microseconds=8)
Note: On block exit the timer records CPU time first, then wall time, so wall time is slightly larger than CPU time even when there is no I/O or scheduling.
Time Function Calls
Use @Timer(). One Measurement per call is appended to the callable’s measurements deque:
>>> from timerun import Timer
>>> @Timer()
... def func(): # function to be measured
... return
...
>>> func()
>>> func.measurements[-1].wall_time.timedelta
datetime.timedelta(microseconds=11)
>>> func.measurements[-1].cpu_time.timedelta
datetime.timedelta(microseconds=8)
Note: Argument maxlen caps how many measurements are kept (e.g. @Timer(maxlen=10)). By default the deque is unbounded.
Callbacks
Optional on_start and on_end callbacks run once per measurement. Both receive the Measurement instance — on_start before timings are set, on_end after. For example:
Print elapsed time when a block finishes:
>>> from timerun import Timer
>>> with Timer(on_end=lambda m: print(m.wall_time.timedelta)):
... pass # code block to be measured
...
0:00:00.000008
Attach a trace id before each call starts:
>>> from uuid import uuid4
>>> from timerun import Timer
>>> @Timer(on_start=lambda m: m.metadata.update(trace_id=uuid4().hex))
... def func():
... return
...
>>> func()
>>> func.measurements[-1].metadata
{'trace_id': '8aa2c000c98843738a2f0d5d3600d052'}
Contributing
Contributions are welcome. See CONTRIBUTING.md for setup, testing, and pull request guidelines.
License
This project is licensed under the MIT License — see the LICENSE file for details.
Metadata
Release files for timerun 0.6.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| timerun-0.6.2.tar.gz | 8.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| timerun-0.6.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.4 kB
Release files / timerun-0.6.2.tar.gz
| Download URL | timerun-0.6.2.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
51fb00243fbd7dabae852369a8d10abe1802a85b318ee105cb8a8854dc80909a
|
|
BLAKE2b-256 checksum How to use checksums |
32e5aab3eaae28bcb565be97a409d7e5da4e6190b5a3adeb2fa33ba2aca88099
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 5, 2026.
Transparency logRelease files / timerun-0.6.2-py3-none-any.whl
| Download URL | timerun-0.6.2-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bc58b86648ed69f4d04a44c2ae038b2686fc34517b26e1135079eb9e40f113a
|
|
BLAKE2b-256 checksum How to use checksums |
ca48715bca7892b23aea8c7c05aa6da273532e1fea1a1a21fffe80650272b923
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 5, 2026.
Transparency log