honch-micropython 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,188 @@
1
+ Metadata-Version: 2.4
2
+ Name: honch-micropython
3
+ Version: 0.3.0
4
+ Summary: Honch analytics SDK for MicroPython
5
+ Author-email: Honch <support@honch.io>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/honch-io/SDK
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+
11
+ # Honch MicroPython SDK
12
+
13
+ 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.
14
+
15
+ ## Status
16
+
17
+ Stable `0.3.0`. The SDK is not standalone pure Python; firmware must be built with the `_honch_core` user C module.
18
+
19
+ This port targets MicroPython. CircuitPython is not covered by the current user C module build flow.
20
+
21
+ ## Build Into MicroPython
22
+
23
+ From a MicroPython checkout, build a port with the Honch user module:
24
+
25
+ ```bash
26
+ make -C ports/unix \
27
+ USER_C_MODULES=/path/to/SDK/ports/micropython/usermod/honch/micropython.cmake
28
+ ```
29
+
30
+ For board firmware, pass the same user module path and freeze the wrapper:
31
+
32
+ ```bash
33
+ make BOARD=MYBOARD \
34
+ USER_C_MODULES=/path/to/SDK/ports/micropython/usermod/honch/micropython.cmake \
35
+ FROZEN_MANIFEST=/path/to/SDK/ports/micropython/manifest.py
36
+ ```
37
+
38
+ The Honch user C module does not set firmware-global MicroPython options such
39
+ as `MICROPY_C_HEAP_SIZE`. Keep heap sizing in the board or host firmware
40
+ configuration. If your board needs additional C heap for Honch and other native
41
+ modules, opt into that value in the board config rather than in the user module.
42
+
43
+ `mip` can install wrapper files from package metadata, but those files require firmware that already contains `_honch_core`.
44
+ Do not install the `honch/` wrapper into `/lib` when it is already frozen into
45
+ the firmware. Keeping both copies wastes the board filesystem and can make
46
+ MicroPython import an older `/lib/honch` package instead of the frozen SDK.
47
+
48
+ ## Basic Usage
49
+
50
+ ```python
51
+ import honch
52
+
53
+ client = honch.Honch(
54
+ api_key="project-key",
55
+ endpoint_url="https://i.honch.io",
56
+ device_id="device-serial-001",
57
+ device_model="ActionCam X1",
58
+ firmware_version="1.2.3",
59
+ event_buffer=bytearray(8192),
60
+ )
61
+
62
+ client.identify("user-123", {"plan": "beta"})
63
+ client.session_start("recording")
64
+ client.track("recording_started", {"mode": "hdr"})
65
+ client.session_end()
66
+ client.flush()
67
+ client.shutdown()
68
+ ```
69
+
70
+ ## Configuration
71
+
72
+ Required:
73
+
74
+ - `api_key`
75
+ - `device_id`
76
+ - `device_model`
77
+ - `firmware_version`
78
+ - `event_buffer`
79
+
80
+ Optional:
81
+ - `endpoint_url` (default `https://i.honch.io`)
82
+ - `environment`
83
+ - `batch_size`
84
+ - `max_queued_events`
85
+ - `max_event_bytes`
86
+ - `transport_timeout_ms` (finite positive milliseconds, clamped to 10000)
87
+ - `flush_interval_seconds`
88
+ - `flush_min_interval_ms` (default `15000`; use `0xFFFFFFFF` to disable for benchmarks)
89
+ - `flush_event_threshold`
90
+ - `flush_retry_initial_ms`
91
+ - `flush_retry_max_ms`
92
+ - `battery_low_threshold`
93
+ - `connectivity_callback` (return false while offline; ticks are skipped and `flush()` raises `OfflineError`)
94
+
95
+ 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.
96
+
97
+ client init does synchronous work on the caller's thread. It validates config,
98
+ initializes the C core against the caller-provided event buffer, derives initial
99
+ state from the supplied device/config values, and queues `$device_boot` before
100
+ returning. It does not perform network I/O; delivery remains cooperative through
101
+ `tick()` or explicit `flush()` calls.
102
+
103
+ Crash reporting is automatic. `client.install_error_hook()` installs a
104
+ best-effort `sys.excepthook` wrapper (on runtimes that expose that hook) that
105
+ emits a one-time `$crash` event for an uncaught exception (`source="exception"`,
106
+ with the exception type in `exception_cause`); the original exception is always
107
+ delivered to the previous hook. `client.report_log_error(message,
108
+ component=...)` emits a bounded, coalesced `$error` event and is intended to be
109
+ driven automatically (e.g. from a `logging.Handler`), not sprinkled through
110
+ application code. The port does not install panic hooks or board-specific
111
+ reset-reason adapters; board reset telemetry belongs in the user module adapter.
112
+
113
+ client.tick() and client.flush() may block for up to the configured transport
114
+ timeout because urequests.post holds the MicroPython interpreter while the HTTP
115
+ request is in progress. Do not call tick() from a latency-sensitive control
116
+ loop, timing-critical sensor loop, UI refresh path, or watchdog-sensitive
117
+ section. Do not call tick() or flush() from ISR-adjacent callbacks or
118
+ high-priority tasks. Schedule it from a low-priority part of the program where a
119
+ stalled interpreter is acceptable for the configured timeout. Explicit timeout
120
+ values above the hard maximum of 10000 ms are clamped.
121
+ Each scheduled tick posts at most one wire chunk, so large queued uploads may
122
+ need several pump iterations to finish.
123
+
124
+ Do not call `tick()` while WLAN is disconnected or the radio is intentionally
125
+ off. If your loop cannot guarantee that, pass `connectivity_callback`; it should
126
+ be fast and read host-owned connectivity state.
127
+
128
+ ## Public API
129
+
130
+ ```python
131
+ client.track(event_name, properties=None)
132
+ client.report_log_error(message, component=None)
133
+ client.install_error_hook()
134
+ client.uninstall_error_hook()
135
+ client.identify(distinct_id, traits=None)
136
+ client.set_property(key, value=None)
137
+ client.session_start(session_name=None)
138
+ client.session_end()
139
+ client.connectivity_changed(connected)
140
+ client.connected()
141
+ client.disconnected()
142
+ client.tick()
143
+ client.flush()
144
+ client.reset()
145
+ client.shutdown()
146
+ client.get_device_id()
147
+ client.queue_stats()
148
+ ```
149
+
150
+ After `identify()`, future events use the new distinct ID. The `$identify`
151
+ event also includes the previous identity as `$anon_distinct_id`, usually the
152
+ device ID, so earlier anonymous events can merge into the identified person.
153
+
154
+ Call `client.tick()` periodically from the device main loop for scheduled flush work. Use `client.flush()` when you want an immediate drain attempt.
155
+
156
+ Properties support typed event values, including strings, integers, floats,
157
+ booleans, lists, dictionaries, null, and `bytes`. Capture may reject bytes
158
+ unless the project enables binary properties. SDK-owned auto property keys
159
+ supplied by users are rejected before compact wire-v2 packetization.
160
+
161
+ ## Storage And Transport
162
+
163
+ The default user C module stores queued events in the caller-provided
164
+ `event_buffer`. Events, `identify()` state, and firmware-version state are
165
+ volatile by default and are lost across reset or power loss. `device_id` is required
166
+ because this port does not persist SDK identity. Pass a caller-provided stable
167
+ device_id from board provisioning, NVS, a filesystem file, or another
168
+ product-owned durable source.
169
+
170
+ That RAM queue is bounded and compact. Consuming a non-tail event uses an O(n)
171
+ memmove per consumed event to keep the caller-provided buffer contiguous; this
172
+ is acceptable at default sizes, but larger buffers and queue limits should be
173
+ measured on the target board.
174
+
175
+ 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`.
176
+
177
+ ## Security
178
+
179
+ 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.
180
+
181
+ ## Tests
182
+
183
+ ```bash
184
+ PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=ports/micropython python3 -m unittest discover \
185
+ -s ports/micropython/tests -t . -v
186
+ ```
187
+
188
+ Full runtime validation requires building MicroPython with `_honch_core` and running the wrapper on that interpreter or firmware.
@@ -0,0 +1,178 @@
1
+ # Honch MicroPython SDK
2
+
3
+ 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.
4
+
5
+ ## Status
6
+
7
+ Stable `0.3.0`. The SDK is not standalone pure Python; firmware must be built with the `_honch_core` user C module.
8
+
9
+ This port targets MicroPython. CircuitPython is not covered by the current user C module build flow.
10
+
11
+ ## Build Into MicroPython
12
+
13
+ From a MicroPython checkout, build a port with the Honch user module:
14
+
15
+ ```bash
16
+ make -C ports/unix \
17
+ USER_C_MODULES=/path/to/SDK/ports/micropython/usermod/honch/micropython.cmake
18
+ ```
19
+
20
+ For board firmware, pass the same user module path and freeze the wrapper:
21
+
22
+ ```bash
23
+ make BOARD=MYBOARD \
24
+ USER_C_MODULES=/path/to/SDK/ports/micropython/usermod/honch/micropython.cmake \
25
+ FROZEN_MANIFEST=/path/to/SDK/ports/micropython/manifest.py
26
+ ```
27
+
28
+ The Honch user C module does not set firmware-global MicroPython options such
29
+ as `MICROPY_C_HEAP_SIZE`. Keep heap sizing in the board or host firmware
30
+ configuration. If your board needs additional C heap for Honch and other native
31
+ modules, opt into that value in the board config rather than in the user module.
32
+
33
+ `mip` can install wrapper files from package metadata, but those files require firmware that already contains `_honch_core`.
34
+ Do not install the `honch/` wrapper into `/lib` when it is already frozen into
35
+ the firmware. Keeping both copies wastes the board filesystem and can make
36
+ MicroPython import an older `/lib/honch` package instead of the frozen SDK.
37
+
38
+ ## Basic Usage
39
+
40
+ ```python
41
+ import honch
42
+
43
+ client = honch.Honch(
44
+ api_key="project-key",
45
+ endpoint_url="https://i.honch.io",
46
+ device_id="device-serial-001",
47
+ device_model="ActionCam X1",
48
+ firmware_version="1.2.3",
49
+ event_buffer=bytearray(8192),
50
+ )
51
+
52
+ client.identify("user-123", {"plan": "beta"})
53
+ client.session_start("recording")
54
+ client.track("recording_started", {"mode": "hdr"})
55
+ client.session_end()
56
+ client.flush()
57
+ client.shutdown()
58
+ ```
59
+
60
+ ## Configuration
61
+
62
+ Required:
63
+
64
+ - `api_key`
65
+ - `device_id`
66
+ - `device_model`
67
+ - `firmware_version`
68
+ - `event_buffer`
69
+
70
+ Optional:
71
+ - `endpoint_url` (default `https://i.honch.io`)
72
+ - `environment`
73
+ - `batch_size`
74
+ - `max_queued_events`
75
+ - `max_event_bytes`
76
+ - `transport_timeout_ms` (finite positive milliseconds, clamped to 10000)
77
+ - `flush_interval_seconds`
78
+ - `flush_min_interval_ms` (default `15000`; use `0xFFFFFFFF` to disable for benchmarks)
79
+ - `flush_event_threshold`
80
+ - `flush_retry_initial_ms`
81
+ - `flush_retry_max_ms`
82
+ - `battery_low_threshold`
83
+ - `connectivity_callback` (return false while offline; ticks are skipped and `flush()` raises `OfflineError`)
84
+
85
+ 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.
86
+
87
+ client init does synchronous work on the caller's thread. It validates config,
88
+ initializes the C core against the caller-provided event buffer, derives initial
89
+ state from the supplied device/config values, and queues `$device_boot` before
90
+ returning. It does not perform network I/O; delivery remains cooperative through
91
+ `tick()` or explicit `flush()` calls.
92
+
93
+ Crash reporting is automatic. `client.install_error_hook()` installs a
94
+ best-effort `sys.excepthook` wrapper (on runtimes that expose that hook) that
95
+ emits a one-time `$crash` event for an uncaught exception (`source="exception"`,
96
+ with the exception type in `exception_cause`); the original exception is always
97
+ delivered to the previous hook. `client.report_log_error(message,
98
+ component=...)` emits a bounded, coalesced `$error` event and is intended to be
99
+ driven automatically (e.g. from a `logging.Handler`), not sprinkled through
100
+ application code. The port does not install panic hooks or board-specific
101
+ reset-reason adapters; board reset telemetry belongs in the user module adapter.
102
+
103
+ client.tick() and client.flush() may block for up to the configured transport
104
+ timeout because urequests.post holds the MicroPython interpreter while the HTTP
105
+ request is in progress. Do not call tick() from a latency-sensitive control
106
+ loop, timing-critical sensor loop, UI refresh path, or watchdog-sensitive
107
+ section. Do not call tick() or flush() from ISR-adjacent callbacks or
108
+ high-priority tasks. Schedule it from a low-priority part of the program where a
109
+ stalled interpreter is acceptable for the configured timeout. Explicit timeout
110
+ values above the hard maximum of 10000 ms are clamped.
111
+ Each scheduled tick posts at most one wire chunk, so large queued uploads may
112
+ need several pump iterations to finish.
113
+
114
+ Do not call `tick()` while WLAN is disconnected or the radio is intentionally
115
+ off. If your loop cannot guarantee that, pass `connectivity_callback`; it should
116
+ be fast and read host-owned connectivity state.
117
+
118
+ ## Public API
119
+
120
+ ```python
121
+ client.track(event_name, properties=None)
122
+ client.report_log_error(message, component=None)
123
+ client.install_error_hook()
124
+ client.uninstall_error_hook()
125
+ client.identify(distinct_id, traits=None)
126
+ client.set_property(key, value=None)
127
+ client.session_start(session_name=None)
128
+ client.session_end()
129
+ client.connectivity_changed(connected)
130
+ client.connected()
131
+ client.disconnected()
132
+ client.tick()
133
+ client.flush()
134
+ client.reset()
135
+ client.shutdown()
136
+ client.get_device_id()
137
+ client.queue_stats()
138
+ ```
139
+
140
+ After `identify()`, future events use the new distinct ID. The `$identify`
141
+ event also includes the previous identity as `$anon_distinct_id`, usually the
142
+ device ID, so earlier anonymous events can merge into the identified person.
143
+
144
+ Call `client.tick()` periodically from the device main loop for scheduled flush work. Use `client.flush()` when you want an immediate drain attempt.
145
+
146
+ Properties support typed event values, including strings, integers, floats,
147
+ booleans, lists, dictionaries, null, and `bytes`. Capture may reject bytes
148
+ unless the project enables binary properties. SDK-owned auto property keys
149
+ supplied by users are rejected before compact wire-v2 packetization.
150
+
151
+ ## Storage And Transport
152
+
153
+ The default user C module stores queued events in the caller-provided
154
+ `event_buffer`. Events, `identify()` state, and firmware-version state are
155
+ volatile by default and are lost across reset or power loss. `device_id` is required
156
+ because this port does not persist SDK identity. Pass a caller-provided stable
157
+ device_id from board provisioning, NVS, a filesystem file, or another
158
+ product-owned durable source.
159
+
160
+ That RAM queue is bounded and compact. Consuming a non-tail event uses an O(n)
161
+ memmove per consumed event to keep the caller-provided buffer contiguous; this
162
+ is acceptable at default sizes, but larger buffers and queue limits should be
163
+ measured on the target board.
164
+
165
+ 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`.
166
+
167
+ ## Security
168
+
169
+ 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.
170
+
171
+ ## Tests
172
+
173
+ ```bash
174
+ PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=ports/micropython python3 -m unittest discover \
175
+ -s ports/micropython/tests -t . -v
176
+ ```
177
+
178
+ Full runtime validation requires building MicroPython with `_honch_core` and running the wrapper on that interpreter or firmware.
@@ -0,0 +1,29 @@
1
+ from .client import Honch
2
+ from .errors import (
3
+ CompressionUnavailableError,
4
+ HonchError,
5
+ InvalidArgumentError,
6
+ NotInitializedError,
7
+ OfflineError,
8
+ RateLimitedError,
9
+ RejectedError,
10
+ ServerError,
11
+ StorageError,
12
+ TransportError,
13
+ )
14
+
15
+ __version__ = "0.3.0"
16
+
17
+ __all__ = (
18
+ "Honch",
19
+ "HonchError",
20
+ "InvalidArgumentError",
21
+ "StorageError",
22
+ "TransportError",
23
+ "OfflineError",
24
+ "RateLimitedError",
25
+ "ServerError",
26
+ "RejectedError",
27
+ "CompressionUnavailableError",
28
+ "NotInitializedError",
29
+ )