Honch analytics SDK for MicroPython
Project description
Honch MicroPython SDK
Stable MicroPython wrapper for the canonical Honch C core. The Python package keeps a small honch.Honch API while behavior comes from the same shared sources used by the ESP-IDF and POSIX ports.
Status
Stable 0.3.1. The SDK is not standalone pure Python; firmware must be built with the _honch_core user C module.
This port targets MicroPython. CircuitPython is not covered by the current user C module build flow.
Build Into MicroPython
From a MicroPython checkout, build a port with the Honch user module:
make -C ports/unix \
USER_C_MODULES=/path/to/SDK/ports/micropython/usermod/honch/micropython.cmake
For board firmware, pass the same user module path and freeze the wrapper:
make BOARD=MYBOARD \
USER_C_MODULES=/path/to/SDK/ports/micropython/usermod/honch/micropython.cmake \
FROZEN_MANIFEST=/path/to/SDK/ports/micropython/manifest.py
The Honch user C module does not set firmware-global MicroPython options such
as MICROPY_C_HEAP_SIZE. Keep heap sizing in the board or host firmware
configuration. If your board needs additional C heap for Honch and other native
modules, opt into that value in the board config rather than in the user module.
mip can install wrapper files from package metadata, but those files require firmware that already contains _honch_core.
Do not install the honch/ wrapper into /lib when it is already frozen into
the firmware. Keeping both copies wastes the board filesystem and can make
MicroPython import an older /lib/honch package instead of the frozen SDK.
Basic Usage
import honch
client = honch.Honch(
api_key="project-key",
endpoint_url="https://i.honch.io",
device_id="device-serial-001",
device_model="ActionCam X1",
firmware_version="1.2.3",
event_buffer=bytearray(8192),
)
client.identify("user-123", {"plan": "beta"})
client.session_start("recording")
client.track("recording_started", {"mode": "hdr"})
client.session_end()
client.flush()
client.shutdown()
Configuration
Required:
api_keydevice_iddevice_modelfirmware_versionevent_buffer
Optional:
endpoint_url(defaulthttps://i.honch.io)environmentbatch_sizemax_queued_eventsmax_event_bytestransport_timeout_ms(finite positive milliseconds, clamped to 10000)flush_interval_secondsflush_min_interval_ms(default15000; use0xFFFFFFFFto disable for benchmarks)flush_event_thresholdflush_retry_initial_msflush_retry_max_msbattery_low_thresholdconnectivity_callback(return false while offline; ticks are skipped andflush()raisesOfflineError)
Python platform=, transport=, battery_callback=, and auto_properties_callback= hooks are not supported by the C-core-derived port. Board behavior belongs in the user module adapters.
client init does synchronous work on the caller's thread. It validates config,
initializes the C core against the caller-provided event buffer, derives initial
state from the supplied device/config values, and queues $device_boot before
returning. It does not perform network I/O; delivery remains cooperative through
tick() or explicit flush() calls.
Crash reporting is automatic. client.install_error_hook() installs a
best-effort sys.excepthook wrapper (on runtimes that expose that hook) that
emits a one-time $crash event for an uncaught exception (source="exception",
with the exception type in exception_cause); the original exception is always
delivered to the previous hook. client.report_log_error(message, component=...) emits a bounded, coalesced $error event and is intended to be
driven automatically (e.g. from a logging.Handler), not sprinkled through
application code. The port does not install panic hooks or board-specific
reset-reason adapters; board reset telemetry belongs in the user module adapter.
client.tick() and client.flush() may block for up to the configured transport timeout because urequests.post holds the MicroPython interpreter while the HTTP request is in progress. Do not call tick() from a latency-sensitive control loop, timing-critical sensor loop, UI refresh path, or watchdog-sensitive section. Do not call tick() or flush() from ISR-adjacent callbacks or high-priority tasks. Schedule it from a low-priority part of the program where a stalled interpreter is acceptable for the configured timeout. Explicit timeout values above the hard maximum of 10000 ms are clamped. Each scheduled tick posts at most one wire chunk, so large queued uploads may need several pump iterations to finish.
Do not call tick() while WLAN is disconnected or the radio is intentionally
off. If your loop cannot guarantee that, pass connectivity_callback; it should
be fast and read host-owned connectivity state.
Public API
client.track(event_name, properties=None)
client.report_log_error(message, component=None)
client.install_error_hook()
client.uninstall_error_hook()
client.identify(distinct_id, traits=None)
client.set_property(key, value=None)
client.session_start(session_name=None)
client.session_end()
client.connectivity_changed(connected)
client.connected()
client.disconnected()
client.tick()
client.flush()
client.reset()
client.shutdown()
client.get_device_id()
client.queue_stats()
After identify(), future events use the new distinct ID. The $identify
event also includes the previous identity as $anon_distinct_id, usually the
device ID, so earlier anonymous events can merge into the identified person.
Call client.tick() periodically from the device main loop for scheduled flush work. Use client.flush() when you want an immediate drain attempt.
Properties support typed event values, including strings, integers, floats,
booleans, lists, dictionaries, null, and bytes. Capture may reject bytes
unless the project enables binary properties. SDK-owned auto property keys
supplied by users are rejected before compact wire-v2 packetization.
Storage And Transport
The default user C module stores queued events in the caller-provided
event_buffer. Events, identify() state, and firmware-version state are
volatile by default and are lost across reset or power loss. device_id is required
because this port does not persist SDK identity. Pass a caller-provided stable
device_id from board provisioning, NVS, a filesystem file, or another
product-owned durable source.
That RAM queue is bounded and compact. Consuming a non-tail event uses an O(n) memmove per consumed event to keep the caller-provided buffer contiguous; this is acceptable at default sizes, but larger buffers and queue limits should be measured on the target board.
Flush sends compact chunk frames to POST <endpoint_url>/capture with Content-Type: application/vnd.honch.chunk, X-Honch-Project-Key, and X-Honch-Stream-Id.
Security
Use HTTPS in production. Verify the board has network, time, and trust setup needed for certificate validation. Keep project keys out of source control, logs, and event properties.
Tests
PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=ports/micropython python3 -m unittest discover \
-s ports/micropython/tests -t . -v
Full runtime validation requires building MicroPython with _honch_core and running the wrapper on that interpreter or firmware.
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 honch_micropython-0.3.1.tar.gz.
File metadata
- Download URL: honch_micropython-0.3.1.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f11a4f97bc49e10eac35a4772efde2a4302fe40548117b37153d8e57e78389f7
|
|
| MD5 |
733c2e12f0e9b735fc63800e430ab469
|
|
| BLAKE2b-256 |
4cba09755b4c5cc0d047c2c509c0be0638d3596d47f8afd224f3552dfd6134bd
|
Provenance
The following attestation bundles were made for honch_micropython-0.3.1.tar.gz:
Publisher:
micropython-publish.yml on honch-io/SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
honch_micropython-0.3.1.tar.gz -
Subject digest:
f11a4f97bc49e10eac35a4772efde2a4302fe40548117b37153d8e57e78389f7 - Sigstore transparency entry: 2045258629
- Sigstore integration time:
-
Permalink:
honch-io/SDK@698961539336c9f3a4e9154b4e732c22d116c0cd -
Branch / Tag:
refs/tags/micropython-v0.3.1 - Owner: https://github.com/honch-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
micropython-publish.yml@698961539336c9f3a4e9154b4e732c22d116c0cd -
Trigger Event:
push
-
Statement type:
File details
Details for the file honch_micropython-0.3.1-py3-none-any.whl.
File metadata
- Download URL: honch_micropython-0.3.1-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeb339f0c8556282a6ae8d0a28c05b0e4b71193d3ca0964f01aeb0ae5eb0911a
|
|
| MD5 |
f513720ace9091bc66fd8e8db1aaf093
|
|
| BLAKE2b-256 |
025d1d053ca6274648192601057eea1923c96c77d47fb67ad1349c7c8492cd77
|
Provenance
The following attestation bundles were made for honch_micropython-0.3.1-py3-none-any.whl:
Publisher:
micropython-publish.yml on honch-io/SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
honch_micropython-0.3.1-py3-none-any.whl -
Subject digest:
eeb339f0c8556282a6ae8d0a28c05b0e4b71193d3ca0964f01aeb0ae5eb0911a - Sigstore transparency entry: 2045259303
- Sigstore integration time:
-
Permalink:
honch-io/SDK@698961539336c9f3a4e9154b4e732c22d116c0cd -
Branch / Tag:
refs/tags/micropython-v0.3.1 - Owner: https://github.com/honch-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
micropython-publish.yml@698961539336c9f3a4e9154b4e732c22d116c0cd -
Trigger Event:
push
-
Statement type: