Skip to content

TimeRun

Structured timing for Python. One small library, no dependencies — wall and CPU time, ready for your logs, metrics, or tracing.


About

You need to measure execution time of Python code in a way that’s trustworthy (wall + CPU, not ad-hoc timers), observable (send to logging, OpenTelemetry, or any pipeline), and low-friction (no new dependencies, works in scripts and production). TimeRun does exactly that.

  • Zero dependencies — Standard library only; safe for libraries and constrained environments.
  • Wall + CPU time — Distinguish real elapsed time from CPU burn (I/O vs CPU-bound).
  • Observability-readyon_start / on_end callbacks and metadata to plug into logging, OpenTelemetry, or any metrics pipeline.

Read the full story for positioning →


Quick start

Install from PyPI

pip install timerun

Measure code block

from timerun import Timer

with Timer() as m:
    pass  # your code

Measure function calls

@Timer()
def my_func():
    pass

my_func()
m = my_func.measurements[-1]  # measurement for last call

Use measurement result

>>> m.wall_time.timedelta
datetime.timedelta(microseconds=11)
>>> m.cpu_time.timedelta
datetime.timedelta(microseconds=8)

Read the reference for API details →


Trust

PyPI version License Coverage Total downloads