Cross-runtime millisecond tick helpers and periodic timing utilities.
Project description
chumicro-timing
Cross-runtime millisecond tick helpers and periodic timing utilities for CircuitPython, MicroPython, and CPython.
All timing is non-blocking — nothing in this library calls time.sleep(). Capture ticks_ms() once per loop iteration and pass the shared timestamp to Heartbeat.poll().
Installation
# CPython (pip)
pip install chumicro-timing
# CircuitPython (circup)
circup bundle-add ChuMicro/chumicro-bundle
circup install chumicro-timing
# MicroPython (mip)
mpremote mip install github:ChuMicro/chumicro-bundle/chumicro_timing
For experimental (pre-release) versions from the develop branch:
pip install chumicro-timing-experimental
circup install chumicro-timing-experimental
mpremote mip install github:ChuMicro/chumicro-bundle/chumicro_timing_experimental
Quick example
from chumicro_timing import Heartbeat, ticks_ms
heartbeat = Heartbeat(period_ms=1000)
while True:
now = ticks_ms()
if heartbeat.poll(now):
print("one second elapsed")
# ... do other work ...
What's included
Tick functions
| Symbol | Description |
|---|---|
ticks_ms() |
Monotonic millisecond counter, wraps every ~6.2 days |
ticks_diff(end, start) |
Wraparound-safe signed difference |
ticks_add(ticks, delta) |
Wraparound-safe addition |
Heartbeat
| Symbol | Description |
|---|---|
Heartbeat(period_ms, ticks=None) |
Periodic timer that fires once per elapsed period |
Heartbeat.poll(now_ms) |
Returns True once per period and advances the timer |
Heartbeat.is_due(now_ms) |
Check whether the period has elapsed (without advancing) |
Heartbeat.reset(now_ms) |
Restart the timer from the given timestamp |
Heartbeat.period_ms |
The configured period (read-only property) |
Testing
| Symbol | Description |
|---|---|
FakeTicks(start_ms=0) |
Deterministic tick source for host-side tests |
FakeTicks.advance(amount_ms) |
Move the fake clock forward |
Platform support
The tick source is selected automatically at import time:
| Priority | Source | Runtime |
|---|---|---|
| 1 | supervisor.ticks_ms |
CircuitPython 7+ |
| 2 | time.ticks_ms |
MicroPython, some CircuitPython builds |
| 3 | time.monotonic_ns |
CPython, some CircuitPython boards |
| 4 | time.monotonic |
Final fallback (float seconds → int ms) |
All sources are masked to a 2²⁹ ms period, so behavior is identical regardless of which source is used.
Testing your code
The chumicro_timing.testing module provides FakeTicks for deterministic host-side tests — no wall-clock waits:
from chumicro_timing import Heartbeat
from chumicro_timing.testing import FakeTicks
fake = FakeTicks()
heartbeat = Heartbeat(period_ms=100, ticks=fake)
now = fake.ticks_ms()
assert heartbeat.poll(now) is False
fake.advance(100)
now = fake.ticks_ms()
assert heartbeat.poll(now) is True
Docs
- User guide — getting started, usage patterns, platform notes
- API reference — full API documentation
- Testing helpers — using
FakeTicksin your tests
Project details
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_timing-0.1.0.tar.gz.
File metadata
- Download URL: chumicro_timing-0.1.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
340ca28dda8c23f8cf7d15b98a2e2c9d230b224e721f1eedcd7660494f24e090
|
|
| MD5 |
8d01fa4cf3eb17f9bc057c8030f1128b
|
|
| BLAKE2b-256 |
cc4d24354e5ad3d7975907621c733454e231c300e6656c0187bd1047ce3f4d77
|
Provenance
The following attestation bundles were made for chumicro_timing-0.1.0.tar.gz:
Publisher:
release.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_timing-0.1.0.tar.gz -
Subject digest:
340ca28dda8c23f8cf7d15b98a2e2c9d230b224e721f1eedcd7660494f24e090 - Sigstore transparency entry: 1239406451
- Sigstore integration time:
-
Permalink:
ChuMicro/ChuMicro@780debcbb227a298fdb7940e424fc3e372e47107 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ChuMicro
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@780debcbb227a298fdb7940e424fc3e372e47107 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file chumicro_timing-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chumicro_timing-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 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 |
48073fed933249c555aac877c02e6a432bc6cf81f3d7efc94ac3e7cdb3ccf32e
|
|
| MD5 |
39490fed9c9077cb0d8bd20d06dfe259
|
|
| BLAKE2b-256 |
b2a7d27519b2c6296509c34de7784057b608e6b4fa070295408f4d7d424edd0c
|
Provenance
The following attestation bundles were made for chumicro_timing-0.1.0-py3-none-any.whl:
Publisher:
release.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_timing-0.1.0-py3-none-any.whl -
Subject digest:
48073fed933249c555aac877c02e6a432bc6cf81f3d7efc94ac3e7cdb3ccf32e - Sigstore transparency entry: 1239406452
- Sigstore integration time:
-
Permalink:
ChuMicro/ChuMicro@780debcbb227a298fdb7940e424fc3e372e47107 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ChuMicro
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@780debcbb227a298fdb7940e424fc3e372e47107 -
Trigger Event:
workflow_dispatch
-
Statement type: