This library provides a backport of Python's `time.monotonic()` function for older Python environments (Python 2 and Python < 3.3). It offers a monotonic clock, guaranteed not to go backward, which is crucial for reliably measuring elapsed time, as it remains unaffected by system clock adjustments such as daylight saving changes. The current version is 1.6. The library is considered stable and complete, with no further updates planned, as `time.monotonic()` is integrated into the standard library for Python 3.3 and newer.
pip install monotonicVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `monotonic` function to measure elapsed time, ensuring that clock adjustments do not affect the duration measurement. It includes a robust import pattern for compatibility across Python 2 and Python 3.3+.
Remove `monotonic` from your dependencies and use `from time import monotonic` directly.
Always calculate durations by subtracting an earlier `monotonic()` call from a later one (e.g., `end_time - start_time`).
Be aware of potential precision limitations on Windows. If nanosecond precision is required on modern Python, `time.monotonic_ns()` might be an alternative (available in Python 3.7+), but this library does not provide that.
Ensure the target platform has a compatible system clock. Common platforms like Linux, Windows, macOS, BSD, and AIX are supported.
Install the library using pip: `pip install monotonic`
For Python versions where `time.monotonic()` is not available, import it from the installed `monotonic` library: `from monotonic import monotonic` or `from monotonic import monotonic as time_monotonic`
Install the `monotonic` backport library (`pip install monotonic`) and then import and use its function: `from monotonic import monotonic` (or alias it, e.g., `from monotonic import monotonic as timer_monotonic`)
No dependency data recorded yet.