Registry / observability / contexttimer

contexttimer

JSON →
library0.3.3pypypi✓ verified 86d ago

A timer context manager measuring the clock wall time of the code block it contains. Version 0.3.3 is the latest, with no recent updates (last release in 2018). The library provides a simple context manager and decorator for timing code blocks, defaulting to wall-clock time. It supports alternative timers via Python's time module.

pip install contexttimer
INSTALL
IMPORT
SIG · CONTEXTTIMER
C
contexttimer
observabilitypythonv0.3.3
Install
2.5s avg
Import
25ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.028s · 19.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.022s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Timer
from contexttimer import Timer
import contexttimer; Timer
Direct import of Timer from contexttimer
timer
from contexttimer import timer
Decorator function, same import style

Basic usage: measure wall time of a code block using a context manager.

from contexttimer import Timer import time with Timer() as t: time.sleep(1) print(f"Elapsed: {t.elapsed}")
Debug
Known issues
gotchaThe default timer is time.perf_counter (Python 3) or time.clock (Python 2). On Python 3.7+, time.clock is removed, but the library handles it. Still, avoid relying on time.clock.
fix
Use a newer library like 'timer' or 'timeit' if you need cross-platform consistency.
affects: 0.3.3
deprecatedThe library is no longer actively maintained (last release 2018). It may have issues with newer Python versions (3.10+).
fix
Consider using 'timer' (pip install timer) or 'timeit' from stdlib.
affects: all
Errors
Common errors & fixes
AttributeError: module 'contexttimer' has no attribute 'Timer'
Incorrect import: using 'import contexttimer' and then 'contexttimer.Timer' but Timer is not a top-level attribute.
fix
Use 'from contexttimer import Timer'
NameError: name 'timer' is not defined
Trying to use the decorator without importing it properly.
fix
Use 'from contexttimer import timer' and then apply @timer
Upgrade
Version history
0.3.3latest on PyPI · released Sep 2, 2016
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
contexttimer — pip install contexttimer · libregistry