Registry / data / nanotime

nanotime

JSON →
library0.5.2pypypi✓ verified 82d ago

nanotime is a Python library that provides a time object with nanosecond precision, storing time as a 64-bit UNIX timestamp (nanoseconds since epoch). It aims to offer a portable, easy-to-process time type with higher precision than standard Unix timestamps. This library was last updated in 2011 and provides a distinct approach to high-precision time compared to the `time.time_ns()` function introduced in Python 3.7.

pip install nanotime
INSTALL
IMPORT
SIG · NANOTIME
N
nanotime
datapythonv0.5.2
Install
2.4s avg
Import
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.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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.103.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`.
fix
Store 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.
fix
For 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.
fix
Understand 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.

Agent activity
14 hits · last 30 days
node
12
Resources
nanotime — pip install nanotime · libregistry