High-precision NTP time synchronization package with CLI tools
Project description
hixbe-time
High-precision NTP time synchronization package with powerful CLI tools
A professional-grade Python package for querying NTP servers and synchronizing system time with network time servers. Built with Hixbe's primary server time.hixbe.com for ultra-reliable time synchronization.
Features
✨ Rich Feature Set
- 🚀 High-performance NTP client
- 📊 Raw packet inspection & analysis
- ⏱️ Precise timestamp conversion (NTP to Unix)
- 🔄 Continuous sync mode with configurable intervals
- 📡 Multiple server support (Hixbe, pool.ntp.org, etc.)
- 📋 Detailed verbose reporting
- 🎨 Beautiful CLI with multiple output formats
- 🔐 Type-safe implementation with dataclasses
- ⚡ Zero external dependencies (uses Python standard library)
Installation
pip install hixbe-time
Development Installation
git clone https://github.com/hixbehq/python-time.git
cd python-time
pip install -e .
Quick Start
CLI Usage
# Get current time from Hixbe server
hixbe-time
# Verbose mode with raw packet details
hixbe-time --verbose
# Output as JSON
hixbe-time --json
# Get time offset (useful for scripts)
hixbe-time --offset
# Continuous synchronization (every 5 seconds)
hixbe-time --continuous
# Custom interval (every 2 seconds)
hixbe-time --continuous --interval 2000
# Query different server
hixbe-time --server pool.ntp.org --verbose
# Show only the offset
hixbe-time --offset
Programmatic Usage
from hixbe_time import NTPClient
# Basic usage
client = NTPClient()
result = client.query_sync()
print(result.parsed.timestamps.transmit.date)
# Get current time
time = client.get_time()
print(time) # datetime object
# Get offset between local and server time
offset_ms = client.get_offset()
print(f'System is {"slow" if offset_ms > 0 else "fast"} by {abs(offset_ms):.0f}ms')
# Custom server
from hixbe_time import NTPClientConfig
config = NTPClientConfig(
host='time.google.com',
timeout=3.0
)
custom_client = NTPClient(config)
time = custom_client.get_time()
API Reference
NTPClient
Main class for NTP queries.
class NTPClient:
def __init__(self, config: Optional[NTPClientConfig] = None):
"""
Initialize NTP client
Args:
config: Client configuration (optional)
"""
def query_sync(self) -> NTPQueryResult:
"""
Query NTP server synchronously
Returns:
NTPQueryResult with complete packet data
"""
def get_time(self) -> datetime:
"""
Get current time from NTP server
Returns:
datetime object with server time
"""
def get_offset(self) -> float:
"""
Get offset between local and server time
Returns:
Offset in milliseconds (positive = local is slow)
"""
NTPClientConfig
Configuration options for NTP client.
@dataclass
class NTPClientConfig:
host: str = 'time.hixbe.com' # NTP server hostname
port: int = 123 # NTP port (default: 123)
timeout: float = 5.0 # Timeout in seconds
fallback_servers: Optional[List[str]] = None # Fallback servers
NTPQueryResult
Result from NTP query containing all response data.
@dataclass
class NTPQueryResult:
buffer: bytes # Raw response buffer
hex_dump: str # Hexadecimal dump
parsed: ParsedNTPPacket # Parsed packet data
server_address: str # Server IP address
client_receive_time: datetime # Client receive timestamp
client_originate_time: datetime # Client send timestamp
used_server: Optional[str] # Server hostname used
CLI Options
usage: hixbe-time [-h] [-s SERVER] [-j] [-v] [-o] [-c] [-i INTERVAL] [--version]
High-precision NTP time synchronization
options:
-h, --help show this help message and exit
-s SERVER, --server SERVER
NTP server to query (default: time.hixbe.com)
-j, --json Output in JSON format
-v, --verbose Verbose output with packet details
-o, --offset Show only time offset in milliseconds
-c, --continuous Continuous synchronization mode
-i INTERVAL, --interval INTERVAL
Interval for continuous mode in milliseconds (default: 5000)
--version show program's version number and exit
Examples
Get Server Time
from hixbe_time import NTPClient
client = NTPClient()
server_time = client.get_time()
print(f"Server time: {server_time}")
Check Time Synchronization
from hixbe_time import NTPClient
client = NTPClient()
offset = client.get_offset()
if abs(offset) > 1000:
print(f"⚠️ WARNING: System clock is off by {offset:.0f}ms")
else:
print(f"✅ System clock is synchronized (offset: {offset:.0f}ms)")
Query Multiple Servers
from hixbe_time import NTPClient, NTPClientConfig
servers = ['time.hixbe.com', 'time.google.com', 'pool.ntp.org']
for server in servers:
config = NTPClientConfig(host=server)
client = NTPClient(config)
try:
result = client.query_sync()
print(f"{server}: {result.parsed.timestamps.transmit.iso}")
except Exception as e:
print(f"{server}: Error - {e}")
Continuous Monitoring
import time
from hixbe_time import NTPClient
client = NTPClient()
while True:
try:
result = client.query_sync()
server_time = result.parsed.timestamps.transmit.date
offset = client.get_offset()
print(f"{server_time.isoformat()} | Offset: {offset:+.0f}ms")
except Exception as e:
print(f"Error: {e}")
time.sleep(5) # Wait 5 seconds
Output Formats
Default Format
======================================================================
🕐 HIXBE TIME SYNC
======================================================================
Server: 154.26.137.94 (time.hixbe.com)
UTC Time: 2025-12-16T04:27:07.341Z
Local Time: 2025-12-16 04:27:07.341000+00:00
Offset: +0.480 seconds
Precision: ±231 (2^x sec)
Stratum: 2
======================================================================
JSON Format
{
"timestamp": 1765859251781,
"iso": "2025-12-16T04:27:31.781Z",
"server": {
"address": "154.26.137.94",
"stratum": 2,
"referenceId": "0xD8EF230C"
},
"offset": 524,
"precision": 231,
"version": 4
}
Verbose Format
Shows detailed packet analysis including:
- All timestamps (reference, originate, receive, transmit)
- Raw NTP timestamp data in hexadecimal
- Complete packet header information
- Full hex dump of the response packet
Requirements
- Python 3.8 or higher
- No external dependencies (uses standard library only)
License
MIT License - see LICENSE file for details.
Author
Hixbe - https://hixbe.com
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Links
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 hixbe_time-1.0.0.tar.gz.
File metadata
- Download URL: hixbe_time-1.0.0.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a37e0cdd5b00812c8bbc54600b347eb5271cff5b862cfcc14869816ad7d4292
|
|
| MD5 |
a7b49f68aac5f71418b6517a805eb7b6
|
|
| BLAKE2b-256 |
5a926be611c86405b509ccc32f1e186293443184b16a9c21f46bb3db0300a11f
|
Provenance
The following attestation bundles were made for hixbe_time-1.0.0.tar.gz:
Publisher:
publish.yml on hixbehq/python-time
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hixbe_time-1.0.0.tar.gz -
Subject digest:
6a37e0cdd5b00812c8bbc54600b347eb5271cff5b862cfcc14869816ad7d4292 - Sigstore transparency entry: 767372287
- Sigstore integration time:
-
Permalink:
hixbehq/python-time@16c9160b36773b7cc5e1ffd5456745ef5c19e4a2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hixbehq
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16c9160b36773b7cc5e1ffd5456745ef5c19e4a2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hixbe_time-1.0.0-py3-none-any.whl.
File metadata
- Download URL: hixbe_time-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d97961cc00c274fbf8c3e8a8864d9e4e3631024a1c1b080f2c4b2aa5518907f
|
|
| MD5 |
c9755720a3ff23077003a489fd748733
|
|
| BLAKE2b-256 |
eea5b7dbe8fa23a9531edf1e66f7a0675325b257594deff01564ca56f56dc65b
|
Provenance
The following attestation bundles were made for hixbe_time-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on hixbehq/python-time
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hixbe_time-1.0.0-py3-none-any.whl -
Subject digest:
8d97961cc00c274fbf8c3e8a8864d9e4e3631024a1c1b080f2c4b2aa5518907f - Sigstore transparency entry: 767372288
- Sigstore integration time:
-
Permalink:
hixbehq/python-time@16c9160b36773b7cc5e1ffd5456745ef5c19e4a2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hixbehq
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16c9160b36773b7cc5e1ffd5456745ef5c19e4a2 -
Trigger Event:
workflow_dispatch
-
Statement type: