Install & Compatibility
Where this runs
tested against v0.5.2 · 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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
nanotime
✓ from nanotime import nanotime
✗ from nanotime import Nanotime
now
✓ from nanotime import now
timestamp
✓ from nanotime import timestamp
Demonstrates how to create a `Nanotime` object, convert it to an integer nanosecond timestamp, convert it to and from a standard `datetime` object, and measure elapsed time.
from nanotime import Nanotime
import datetime
# Get current time with nanosecond precision
now = Nanotime.now()
print(f"Current nanotime: {now}")
# Convert to nanoseconds (integer)
ns_since_epoch = int(now)
print(f"Nanoseconds since epoch: {ns_since_epoch}")
# Convert to datetime object (loses nanosecond precision beyond microseconds)
dt_obj = now.datetime()
print(f"Converted to datetime: {dt_obj}")
# Create from a datetime object
some_dt = datetime.datetime(2023, 1, 1, 12, 30, 0, 123456)
nt_from_dt = Nanotime.from_datetime(some_dt)
print(f"Nanotime from datetime: {nt_from_dt}")
# Calculate duration
import time
start_nt = Nanotime.now()
time.sleep(0.001) # Simulate some work
end_nt = Nanotime.now()
delta_ns = int(end_nt) - int(start_nt)
print(f"Time elapsed (nanoseconds): {delta_ns}")
Debug
Known issues
breakingThe `nanotime` library provides its own `Nanotime` object. Direct integration with standard Python `datetime` objects will result in loss of nanosecond precision as `datetime` objects only support microseconds. This is a fundamental limitation of `datetime`.fixStore time as a `Nanotime` object or as a raw nanosecond integer if full precision is required. Convert to `datetime` only when microsecond precision is acceptable for display or interoperability with other libraries.
affects: All versions
deprecatedThe `nanotime` library has not been updated since 2011. Python 3.7+ introduced `time.time_ns()`, `monotonic_ns()`, `perf_counter_ns()`, and `process_time_ns()` into the standard library, providing native nanosecond precision integers. These standard library functions are generally preferred for new development requiring nanosecond resolution.fixFor new projects on Python 3.7 or later, consider using `time.time_ns()` and related functions from the standard `time` module for nanosecond-level timestamps, rather than relying on this unmaintained third-party library.
affects: All versions of nanotime, for Python 3.7+
gotchaThe internal representation of `Nanotime` is a 64-bit unsigned integer representing nanoseconds since the Unix epoch. While this provides a theoretical range of approximately 584 years, the library's design assumes an epoch of 1970 and may behave unexpectedly or have practical limits for dates far outside the 1970-2554 range.fixUnderstand the intended range and representation. For extremely broad date ranges, other time representations might be more suitable or robustly supported.
affects: All versions
Upgrade
Version history
0.5.2latest on PyPI · released Sep 22, 2011
Audit
Dependencies
No dependency data recorded yet.