codetiming
A flexible, customizable timer for your Python code.
What it is and what it does
codetiming provides a Timer class for measuring code execution time in Python. It supports three usage patterns—as a standalone class with explicit start/stop calls, as a context manager for timing code blocks, and as a decorator for timing function calls. The Timer accepts optional arguments to customize output formatting (via a text template), redirect output to a logger function, and optionally display text when the timer starts.
The package includes named timer aggregation: when you create a Timer with a name, elapsed times accumulate in a class-level dictionary (Timer.timers) that provides statistics methods like mean, median, min, max, stdev, and count. The text formatting is template-based using .format() rather than f-strings, and can be a callable for custom time formatting. A single runtime dependency on dataclasses ensures compatibility with older Python versions.
Use it for:
- Measure execution time of specific code blocks during development and debugging without external profiling tools
- Track performance of repeated operations and gather statistics (mean, max, stdev) across multiple runs
- Add timing instrumentation to functions using decorators for quick performance monitoring
- Redirect timer output to logging frameworks instead of print for integration with application logging
- Benchmark different implementations by timing them with named timers and comparing accumulated statistics
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Measures elapsed time in Python code using a flexible Timer class that works as a decorator, context manager, or standalone object, with customizable output formatting and named timer aggregation.
Yes, if you need a lightweight, zero-configuration timer for development and learning. The package is stable and has no known vulnerabilities, but install with the understanding that it is no longer maintained—no bug fixes or feature updates will be released. For production performance monitoring, consider a more actively maintained alternative.
Install
codetiming on PyPI
pip
pip install codetiminguv
uv add codetimingpoetry
poetry add codetimingInstalling codetiming
Before you install
Installation is straightforward with no compiled dependencies. However, the package has been abandoned since November 2022 (over 1375 days without updates), so no active maintenance or bug fixes should be expected.
License in practice
Licensed under MIT (permissive), which allows free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
from codetiming import Timer
# As a context manager
with Timer(name="example"):
# Code to time
pass
# As a decorator
@Timer(name="function")
def my_function():
pass
# As a class
t = Timer()
t.start()
# Code to time
elapsed = t.stop()
Verify before relying
- Whether the package works correctly with Python versions beyond 3.11 despite no recent releases
- Current compatibility with modern Python async/await patterns
- Whether accumulated timer data in Timer.timers persists correctly across different execution contexts
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — dataclasses |
| Maintenance | abandoned — 1,375 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,024,712/month — #4,485 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: codetiming-1.4.0-py3-none-any.whl
Keywords: timer, class, contextmanager, decorator
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
stopwatch.pyProvides a simple stopwatch timer that measures…
permissive · top 15,000 on PyPI
monotonicProvides a monotonic clock function that…
permissive · top 5,000 on PyPI
line-profilerline_profiler measures execution time on a…
permissive · top 5,000 on PyPI
interruptingcowInterrupts long-running Python code by raising…
permissive · top 15,000 on PyPI
throttlerProvides rate limiting, concurrency limiting,…
permissive · top 5,000 on PyPI
easydevProvides a collection of utility functions and…
permissive · top 15,000 on PyPI
AutologgingAutologging provides decorators to…
permissive · top 15,000 on PyPI
pytest-timerPytest plugin that measures and reports the…
permissive · top 15,000 on PyPI
pytimeparse2Parses human-readable time expressions (like…
permissive · top 5,000 on PyPI
waiterWaiter provides iteration-based retry and…
permissive · top 15,000 on PyPI