{"id":23055,"library":"contexttimer","title":"contexttimer","description":"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.","status":"maintenance","version":"0.3.3","language":"python","source_language":"en","source_url":"https://github.com/brouberol/contexttimer","tags":["timer","context-manager","benchmarking","wall-time"],"install":[{"cmd":"pip install contexttimer","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Direct import of Timer from contexttimer","wrong":"import contexttimer; Timer","symbol":"Timer","correct":"from contexttimer import Timer"},{"note":"Decorator function, same import style","wrong":"","symbol":"timer","correct":"from contexttimer import timer"}],"quickstart":{"code":"from contexttimer import Timer\nimport time\n\nwith Timer() as t:\n    time.sleep(1)\nprint(f\"Elapsed: {t.elapsed}\")","lang":"python","description":"Basic usage: measure wall time of a code block using a context manager."},"warnings":[{"fix":"Use a newer library like 'timer' or 'timeit' if you need cross-platform consistency.","message":"The 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.","severity":"gotcha","affected_versions":"0.3.3"},{"fix":"Consider using 'timer' (pip install timer) or 'timeit' from stdlib.","message":"The library is no longer actively maintained (last release 2018). It may have issues with newer Python versions (3.10+).","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'from contexttimer import Timer'","cause":"Incorrect import: using 'import contexttimer' and then 'contexttimer.Timer' but Timer is not a top-level attribute.","error":"AttributeError: module 'contexttimer' has no attribute 'Timer'"},{"fix":"Use 'from contexttimer import timer' and then apply @timer","cause":"Trying to use the decorator without importing it properly.","error":"NameError: name 'timer' is not defined"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}