ntps
Modern, type-safe, zero-dependency python library for implementing a network time protocol (NTP) stratum 0 server.
Installation
pip install ntps
or
using your preferred environment / package manager of choice, e.g., poetry, conda or uv:
poetry add ntps
conda install ntps
uv add ntps
Usage
There are two main components in the ntps library: the NTP server and the NTP client.
The NTP server is used to create an NTP server that can be used to synchronize time across a network. The NTP client is used to query an NTP server for the current time.
The following is an example of how to use the ntps library to create an NTP server and client:
Server
from asyncio import get_running_loop, run
from time import time
from ntps import NTPServer
# Define a custom NTP server that uses GPS-synced time as the reference time, and a
# stratum level of 0:
class GNSSStratum0NTPServer(NTPServer):
# Set the reference identifier of the NTP server:
refid = "GPS"
# Set the stratum level of the NTP server:
stratum = 0
def get_ntp_time(self) -> float:
# Replace this with your actual GPS-synced time retrieval:
return time()
async def main() -> None:
# Retrieve the current running asynchronous event loop:
loop = get_running_loop()
# Create a UDP server endpoint on all interfaces at port 123 using your
# custom implementation (e.g., GNSSStratum0NTPServer):
transport, _ = await loop.create_datagram_endpoint(
lambda: GNSSStratum0NTPServer(),
local_addr=('0.0.0.0', 123),
)
Client
from ntps import NTPClient, NTPPacket
async def main() -> None:
# Create a new NTP client instance:
client = NTPClient(endpoint="0.0.0.0", port=123)
# Send an NTP request to the specified NTP server (e.g., 0.pool.ntp.org):
packet: NTPPacket = client.query()
# Print the response packet from the NTP server:
print(packet)
As the ntps instance is fully typed, you can use your IDE's autocompletion to see all the available methods and properties.
We have also provided further usage examples in the examples directory.
Milestones
- Implement NTP server
- Implement NTP client
- Implement NTP packet
- Implement kiss-of-death (KoD) packet
- Implement NTP authentication
- Implement NTP broadcast
- Implement NTP multicast
- Implement NTP symmetric mode
Miscellaneous
For more information on the NTP protocol, please refer to the RFC 5905 document.
License
This project is licensed under the terms of the MIT license.
Metadata
Release files for ntps 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ntps-0.5.0.tar.gz | 33.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ntps-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.3 kB
Release files / ntps-0.5.0.tar.gz
| Download URL | ntps-0.5.0.tar.gz |
|---|---|
| Size | 33.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cbc1b808fa0313d8ee21614476cb7aa36f8ca6b118f6267fbd6d6d09e3a26205
|
|
BLAKE2b-256 checksum How to use checksums |
52a75dfc672b18fdcf7f64a29fa4abfe9be1b62c1ba1fb40ca68bddad4c76794
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 28, 2025.
Transparency logRelease files / ntps-0.5.0-py3-none-any.whl
| Download URL | ntps-0.5.0-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e260bd9d4a2476890887c77eaaf6e5d9302f27c21a174fd83619824b252b55d1
|
|
BLAKE2b-256 checksum How to use checksums |
2f6b4da63fd3c34067e8dbdaaa676ab4db3f4a0c5e960c0b9b3c85a2ec29debd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 28, 2025.
Transparency log