chumicro-timing
Timers that don't block. Your loop keeps ticking.
Capture ticks_ms() once per loop pass, hand it to a Rate or a Deadline, and you've got clean drift-free timing on CircuitPython, MicroPython, or CPython. Tick-source detection is automatic, wraparound is handled, and there are no dependencies on anything else in ChuMicro. It's where every other library starts.
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_timing
# MicroPython
mpremote mip install github:ChuMicro/ChuMicro-Bundle/chumicro_timing
# CPython
pip install chumicro-timing
For bundle setup, pre-compiled .mpy bundles, the experimental channel, and details on PyPI naming, see the chumicro INSTALL guide.
Quick example
from chumicro_timing import Rate, ticks_ms
rate = Rate(1000, ticks_ms())
while True:
now = ticks_ms()
if rate.due(now):
print("one second elapsed")
# ... do other work ...
What's included
Tick functions
| Symbol | Description |
|---|---|
ticks_ms() |
Current time in milliseconds (keeps counting even when it wraps around) |
ticks_diff(end, start) |
Time elapsed between two tick values (handles wraparound correctly) |
ticks_add(ticks, delta) |
Add milliseconds to a tick value (handles wraparound correctly) |
Value objects
| Symbol | Description |
|---|---|
Deadline(period_ms, now_ms) |
A single armed timeout: expired(now) / remaining(now) / reset(now) |
Rate(period_ms, now_ms) |
Drift-free periodic cadence; due(now) fires at most once per period |
Wait vocabulary (chumicro_timing.waits)
Opt-in completion-wait vocabulary for generator flows. Import it explicitly.
| Symbol | Description |
|---|---|
Signal() |
A completion flag: set(value) / clear() / ready(now), with is_set and value readable directly |
wait_for(signal, deadline_ms=None) |
Generator suspension helper: yield from wait_for(signal) |
Testing
| Symbol | Description |
|---|---|
FakeTicks(start_ms=0) |
Deterministic tick source for host-side tests |
FakeTicks.advance(amount_ms) |
Move the fake clock forward |
Where this fits
Leaf: no upstream ChuMicro deps. Everything in ChuMicro that owns time depends on it: runner, sockets, ntp, requests, http_server, mqtt, websockets.
Platform support
You don't need to pick a tick source. The library picks the best one available on your runtime. Behavior is identical regardless of which source is used.
| Source | Runtime |
|---|---|
supervisor.ticks_ms |
CircuitPython 7+ |
time.ticks_ms |
MicroPython, some CircuitPython builds |
time.monotonic_ns |
CPython, some CircuitPython boards |
time.monotonic |
Final fallback (float seconds → int ms) |
The library tries them top-to-bottom and uses the first one your runtime supports.
Technical detail: tick wraparound
All sources are masked to a 2²⁹ ms period (~6.2 days). ticks_diff and ticks_add handle wraparound correctly, so your timers keep working even when the counter rolls over.
Testing your code
The chumicro_timing.testing module provides FakeTicks for deterministic host-side tests with no wall-clock waits:
from chumicro_timing import Rate
from chumicro_timing.testing import FakeTicks
fake = FakeTicks()
rate = Rate(100, fake.ticks_ms())
assert rate.due(fake.ticks_ms()) is False
fake.advance(100)
assert rate.due(fake.ticks_ms()) is True
Examples
| Example | What it shows |
|---|---|
rate_blink.py |
Basic periodic Rate loop |
multiple_rates.py |
Multiple Rate timers at different rates |
timeout_check.py |
One-shot deadline check using ticks_diff |
debounce.py |
Simulated button debounce |
periodic_tick.py |
Manual periodic loop (the same logic Rate wraps internally) |
phase_locked_tick.py |
Drift-free deadline carrier, same period across late loops |
circuitpython_blink.py |
LED blink on CircuitPython hardware |
circuitpython_debounce.py |
GPIO button debounce on CircuitPython |
micropython_blink.py |
LED blink on MicroPython hardware |
micropython_debounce.py |
GPIO button debounce on MicroPython |
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-timing
- Bundle: ChuMicro-Bundle (CircuitPython & MicroPython)
- Experimental bundle: ChuMicro-Bundle-Experimental
- Source: libraries/timing
License
Metadata
Release files for chumicro-timing 0.8.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chumicro_timing-0.8.3.tar.gz | 23.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chumicro_timing-0.8.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.6 kB
Release files / chumicro_timing-0.8.3.tar.gz
| Download URL | chumicro_timing-0.8.3.tar.gz |
|---|---|
| Size | 23.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3cb2e3e683a4929f4153f58ee47409021884c8b0be6545a547114ea1f35b2f7c
|
|
BLAKE2b-256 checksum How to use checksums |
c4168487bacbe80725a04f38d4a7d6024ef748afa7b030aa68f5c55582211c17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 18, 2026.
Transparency logRelease files / chumicro_timing-0.8.3-py3-none-any.whl
| Download URL | chumicro_timing-0.8.3-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b9752b838cd0f4b1a2c64aed2dc8f78c87f69a6ceaa30749fcb3434d6038dcc
|
|
BLAKE2b-256 checksum How to use checksums |
1ff4803614f063a83e45e88c52e7f3b9a7152aa3979238443718406ac5bf0e2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 18, 2026.
Transparency log