chumicro-ntp
An SNTP (Simple Network Time Protocol) client that runs in your tick loop without blocking it.
Polls one server, advances on each runner tick, and gives you the unix seconds when the response lands. Pure Python, no compiled module, no time.sleep(). Your LED keeps blinking through the network hop. UDP transport is injected so apps with a custom socket layer don't drag chumicro-sockets into the device deploy.
Part of the ChuMicro family: small, focused Python libraries for microcontrollers and laptops. Browse all libraries.
Install
# CircuitPython (after `circup bundle-add ChuMicro/ChuMicro-Bundle`)
circup install chumicro_ntp
# MicroPython
mpremote mip install github:ChuMicro/ChuMicro-Bundle/chumicro_ntp
# CPython
pip install chumicro-ntp
For bundle setup, pre-compiled .mpy bundles, the experimental channel, and details on PyPI naming, see the chumicro INSTALL guide.
Quick example
from chumicro_ntp import NTPClient
from chumicro_sockets import udp_socket
from chumicro_timing import ticks_ms
# On CircuitPython pass radio=wifi.adapter.radio (your chumicro-wifi
# WifiService's board radio); the kwarg is ignored on MP / CPython.
sock = udp_socket(radio=None)
sock.setblocking(False) # required: a blocking recv wedges on packet loss
client = NTPClient(socket=sock, server="pool.ntp.org")
request = client.query()
while not request.done:
if client.check(ticks_ms()):
client.handle(ticks_ms())
print("unix seconds:", request.unix_seconds)
chumicro_sockets.udp_socket builds the default bound UDP socket. Pass any object satisfying the sendto / recvfrom_into / close / setblocking contract (see NTPClient's docstring) to NTPClient(socket=...). chumicro_sockets.udp_socket and chumicro_sockets.testing.FakeUDPSocket are the built-in producers. NTPClient.from_config wires that default itself through the shared chumicro_sockets.sockets_factory module, imported lazily, so apps with a custom UDP transport keep chumicro-sockets out of their device deploy.
What's included
| Symbol | Purpose |
|---|---|
NTPClient(socket, *, server="pool.ntp.org", port=123, timeout_ms=5000, ticks=None) |
Runner-shaped SNTP client. Single in-flight query at a time; mirrors HttpClient.busy. |
NTPClient.query() |
Send a request; returns a NTPResult to poll. |
NTPClient.check(now_ms) / handle(now_ms) |
Runner contract: handle drains the recv socket and detects timeouts. |
NTPClient.cancel() |
Abort an in-flight query. |
NTPResult |
Per-query handle. done, unix_seconds, error. |
NTPError |
OSError subclass raised on protocol-level failures (short/malformed response, kiss-of-death, timeout, cancel). |
chumicro_sockets.udp_socket(radio=None) |
Built-in bound UDP socket for NTPClient(socket=...). NTPClient.from_config reaches it through the shared chumicro_sockets.sockets_factory; a custom transport skips that import and keeps chumicro-sockets out of the deploy. |
Where this fits
Depends on chumicro-sockets for UDP transport and chumicro-timing for ticks. A single pip install chumicro-ntp brings the stack. Used directly in app code; no other ChuMicro library depends on it.
Platform support
Pure-Python; runs identically on CPython, MicroPython, and CircuitPython.
Examples
| Example | What it shows |
|---|---|
examples/ntp_query.py |
Real query against pool.ntp.org: wifi up, UDP socket via factory, runner-shaped poll loop. Cross-runtime (CP + MP). |
Contributing
Issues, bug reports, and pull requests are welcome, and so is "I ran it on this board and here's what happened", some of the most useful feedback a hardware project can get. Development happens in the ChuMicro repository, whose contributing guide covers setup and the test workflow.
Docs
📖 Stable docs · Experimental docs
Find this library
- PyPI: chumicro-ntp
- Bundle: ChuMicro-Bundle (CircuitPython & MicroPython)
- Experimental bundle: ChuMicro-Bundle-Experimental
- Source: libraries/ntp
License
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 chumicro_ntp-0.15.0.tar.gz.
File metadata
- Download URL: chumicro_ntp-0.15.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
056ffaf975c20d543702d8c8a7a82c9fd042127f0df0c2c7241c918e6c63bdf4
|
|
| MD5 |
55b8d62dad47ade9979bfd9be6149a4d
|
|
| BLAKE2b-256 |
30c5bb9b30f408ddb0b07005841dde7a15782fe4f8e772816d4f96c22b4db39c
|
Provenance
The following attestation bundles were made for chumicro_ntp-0.15.0.tar.gz:
Publisher:
promote.yml on ChuMicro/ChuMicro
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chumicro_ntp-0.15.0.tar.gz -
Subject digest:
056ffaf975c20d543702d8c8a7a82c9fd042127f0df0c2c7241c918e6c63bdf4 - Sigstore transparency entry: 2499704900
- Sigstore integration time:
-
Permalink:
ChuMicro/ChuMicro@9fe3aa25f1d3ad43e829d9061bd88df65d021806 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ChuMicro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
promote.yml@9fe3aa25f1d3ad43e829d9061bd88df65d021806 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file chumicro_ntp-0.15.0-py3-none-any.whl.
File metadata
- Download URL: chumicro_ntp-0.15.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f58a1370529769da37b8812b5fd76aa4bae0155dd090f1a79767f585613274e8
|
|
| MD5 |
a0c05eb99b5d73d38059fb9911490bba
|
|
| BLAKE2b-256 |
3d744dc97b7fb40a2ad314cf037d9976f40c142b35405559c2e1c870b83c6738
|
Provenance
The following attestation bundles were made for chumicro_ntp-0.15.0-py3-none-any.whl:
Publisher:
promote.yml on ChuMicro/ChuMicro
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chumicro_ntp-0.15.0-py3-none-any.whl -
Subject digest:
f58a1370529769da37b8812b5fd76aa4bae0155dd090f1a79767f585613274e8 - Sigstore transparency entry: 2499704906
- Sigstore integration time:
-
Permalink:
ChuMicro/ChuMicro@9fe3aa25f1d3ad43e829d9061bd88df65d021806 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ChuMicro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
promote.yml@9fe3aa25f1d3ad43e829d9061bd88df65d021806 -
Trigger Event:
workflow_dispatch
-
Statement type: