Add your description here
Project description
Clockbound Python Library
This a library to consume ClockBound time error bounds in pure Python.
Instead of operating on timestamps directly, you can call clockbound.now() to get a clockbound.TimeBound object that represents the earliest and latest possible times according to ClockBound.
You can then use two TimeBound objects to deconflict events from eachother.
This allows you to implement interesting algorithms that do an end-run around several distributed systems problems, similar to how Google uses TrueTime in Spanner.
Any system that uses chrony can use ClockBound, and therefore this library, to get time bounds with very low overhead. The error bounds will narrow as your chrony time source is improved, with the good results obtained by using the Amazon Time Sync Service NTP Service (automatically used on AWS EC2 instances). Going beyond that and using the PTP Hardware Clock will yield the best results.
Minimizing your NTP error is outside of the scope of this project, but you can expect the following bounds in practice:
- PC with internet NTP: +/- 10-50 ms
- EC2 using default Amazon Time Sync Service: +/- 500 µs - 2 ms
- EC2 with PTP Hardware Clock: "+/- 40 µs"
API
To use this library, you need the ClockBound daemon running on your system. This library will not work without it providing time bounds via shared memory.
For most purposes, you can use the clockbound.now() function to get TimeBound objects from
the default global Clockbound instance.
This library will construct the global on first use.
import clockbound
from clockbound import TimeBound
tb: TimeBound = clockbound.now()
print(str(tb))
# Output:
# 2025-11-17T06:37:47.679501+00:00 ± 506 µs
TimeBound objects have the following properties:
earliest: (int) The earliest possible time in nanoseconds since the epoch.latest: (int) The latest possible time in nanoseconds since the epoch.error_ns: (int) The error in nanoseconds.earliest_dt: (datetime tz-aware UTC) A convenience accessor to get the earliest time as a datetime rounded down to microseconds.latest_dt: (datetime tz-aware UTC) A convenience accessor to get the latest time as a datetime rounded up to microseconds.__str__(): A string representation with the error margin included.
Errors
All errors subclass clockbound.ClockboundError. There are error subclasses for finer grained error handling, but they are not exposed as part of the public API at this time.
You can get errors for the following reasons:
- The daemon is not running or shared memory cannot be accessed.
- ClockBound reports that the clock is not synchronized, and we cannot give out guaranteed time bounds.
- The requested time is voided (past the void_after time). This should be rare in practice, but can happen if the daemon crashes or is really slow to restart. We cannot get fresh time bounds and the last known bounds are now invalid.
Performance
Calling clockbound.now() is acceptable fast, allowing 350,000 calls per second on a fairly modest consumer machine.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clockbound-0.3.0.tar.gz.
File metadata
- Download URL: clockbound-0.3.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bbbf6c8a96a90fcc09e097658f3cc5ec015f1c6002de4ee11d9cd8ea59b1cda
|
|
| MD5 |
03519a1d2f5940bf5c194dff69d5ce09
|
|
| BLAKE2b-256 |
90f8a7911ec26d122110a6a635d6b5df918a7181e4fcba076d2e0e1329ca6412
|
File details
Details for the file clockbound-0.3.0-py3-none-any.whl.
File metadata
- Download URL: clockbound-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80788887743e161bf082898b78292ae18bca3b73733c18f6f77ea784a4abfa02
|
|
| MD5 |
f35077cd4fb3f05452cbf1d3272d959f
|
|
| BLAKE2b-256 |
4e294195806221ccfc50502a524b868fd46cce57ee046cc68c042a7960d66e6a
|