intempt 2.1.0__tar.gz → 3.1.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.
- intempt-3.1.0/.claude/lane.json +1 -0
- {intempt-2.1.0 → intempt-3.1.0}/ARCHITECTURE.md +32 -30
- {intempt-2.1.0 → intempt-3.1.0}/CHANGELOG.md +63 -0
- {intempt-2.1.0 → intempt-3.1.0}/PKG-INFO +43 -34
- {intempt-2.1.0 → intempt-3.1.0}/README.md +42 -33
- {intempt-2.1.0 → intempt-3.1.0}/docs/CONVENTIONS.md +14 -9
- {intempt-2.1.0 → intempt-3.1.0}/examples/bare/send.py +15 -4
- {intempt-2.1.0 → intempt-3.1.0}/examples/basic/app.py +7 -5
- {intempt-2.1.0 → intempt-3.1.0}/scripts/e2e.py +32 -3
- {intempt-2.1.0 → intempt-3.1.0}/src/intempt/__init__.py +8 -2
- intempt-3.1.0/src/intempt/_buffer.py +297 -0
- {intempt-2.1.0 → intempt-3.1.0}/src/intempt/_client.py +246 -100
- {intempt-2.1.0 → intempt-3.1.0}/src/intempt/_config.py +21 -0
- intempt-3.1.0/src/intempt/_delivery.py +137 -0
- {intempt-2.1.0 → intempt-3.1.0}/src/intempt/_errors.py +12 -7
- {intempt-2.1.0 → intempt-3.1.0}/src/intempt/_flags.py +15 -4
- {intempt-2.1.0 → intempt-3.1.0}/src/intempt/_transport.py +100 -35
- {intempt-2.1.0 → intempt-3.1.0}/tests/conftest.py +45 -6
- {intempt-2.1.0 → intempt-3.1.0}/tests/test_bare_sample.py +3 -3
- {intempt-2.1.0 → intempt-3.1.0}/tests/test_buffer.py +188 -283
- {intempt-2.1.0 → intempt-3.1.0}/tests/test_client.py +57 -8
- intempt-3.1.0/tests/test_delivery_failure.py +628 -0
- intempt-3.1.0/tests/test_e2e_script.py +68 -0
- {intempt-2.1.0 → intempt-3.1.0}/tests/test_example_app.py +10 -1
- {intempt-2.1.0 → intempt-3.1.0}/tests/test_flags.py +248 -3
- intempt-3.1.0/tests/test_thresholds.py +144 -0
- intempt-3.1.0/tests/test_transport.py +448 -0
- intempt-2.1.0/src/intempt/_buffer.py +0 -330
- intempt-2.1.0/tests/test_thresholds.py +0 -393
- intempt-2.1.0/tests/test_transport.py +0 -197
- {intempt-2.1.0 → intempt-3.1.0}/.github/workflows/autopr.yaml +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/.github/workflows/blu-bot-pipeline-caller.yml +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/.github/workflows/e2e.yml +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/.github/workflows/ff-merge.yml +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/.github/workflows/release.yml +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/.github/workflows/tests.yml +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/.gitignore +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/LICENSE +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/NOTICE +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/docs/TESTING.md +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/examples/README.md +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/pyproject.toml +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/scripts/check-no-local-bucketing.mjs +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/scripts/mutation_gate.py +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/scripts/no-local-bucketing-allow.json +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/src/intempt/_util.py +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/tests/__init__.py +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/tests/test_bucketing_guard.py +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/tests/test_config.py +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/tests/test_credential_guard.py +0 -0
- {intempt-2.1.0 → intempt-3.1.0}/tests/test_messages.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"lane":"BUG","ref":"INT-7291","test":"tests/test_transport.py"}
|
|
@@ -37,7 +37,7 @@ Identical across all three, allowing for language idiom (`snake_case` in Python,
|
|
|
37
37
|
| `consent.grant(options)` / `consent.revoke(options)` | `POST …/consents/data` |
|
|
38
38
|
| `ecommerce.product_viewed / added_to_cart / ordered` | `POST …/track` |
|
|
39
39
|
| `recommend(options)` | `POST …/feeds/{feedId}/data` |
|
|
40
|
-
| `opt_in()` / `opt_out()` / `is_opted_in()` | — |
|
|
40
|
+
| `opt_in()` / `opt_out()` / `is_opted_in()` / `has_opted_out()` | — |
|
|
41
41
|
| `flush()` / `close()` | — |
|
|
42
42
|
| `set_config(patch)` / `config` / `buffered` | — |
|
|
43
43
|
|
|
@@ -58,32 +58,32 @@ path is `…/track` rather than `…/sources/{id}/track`.
|
|
|
58
58
|
|
|
59
59
|
## Delivery guarantees
|
|
60
60
|
|
|
61
|
-
###
|
|
61
|
+
### Failed sends are reported, not raised (INT-7444)
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
A write never raises for a delivery problem, in batch or direct mode: it returns
|
|
64
|
+
whether the event was accepted, and the `on_delivery_failure` listener hears each
|
|
65
|
+
batch's final outcome once. `flush()`/`close()` return `FlushResult(sent, failed)`.
|
|
66
|
+
Bad arguments and a closed client still raise. Ruling: CONTRACT-R2 S2, the same in
|
|
67
|
+
every Intempt SDK.
|
|
65
68
|
|
|
66
|
-
###
|
|
69
|
+
### Send policy (INT-7436)
|
|
70
|
+
|
|
71
|
+
One table in `_delivery.py` for batch mode, direct mode and consent:
|
|
67
72
|
|
|
68
73
|
| response | behaviour |
|
|
69
74
|
| -------- | --------- |
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
|
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
against full is unreachable and the reduction becomes permanent. Widen by doubling
|
|
83
|
-
after 10 consecutive successful sends that filled the width.
|
|
84
|
-
2. **The drop tally must not change behaviour.** It is diagnostic only. Stopping on it
|
|
85
|
-
strands the queue; pinning the width to 1 on it caps throughput to one event per
|
|
86
|
-
round trip and loses more events than it saves requests.
|
|
75
|
+
| 2xx | sent |
|
|
76
|
+
| 503, 429 | resend once after `Retry-After` clamped to 1–60 s (1 s when absent); a wait over 5 s drops instead of sleeping |
|
|
77
|
+
| any other status (400, 401–404, 408, 413, 500, 502, 504, …) | drop and report |
|
|
78
|
+
| timeout or broken connection after the request was written | drop and report; the server may already have it |
|
|
79
|
+
| never reached the server (DNS, refused, connect timeout) | batch mode keeps the batch until the next timed flush (`flush_ms`) or an explicit `flush()`, and reaching `size` meanwhile sends nothing; direct mode drops and reports |
|
|
80
|
+
| a pooled keep-alive socket the server already closed | reconnect once at once and send on the fresh socket |
|
|
81
|
+
|
|
82
|
+
At `max_queue` the oldest queued event that no send is carrying is dropped and reported
|
|
83
|
+
`dropped`, and the new event is queued.
|
|
84
|
+
|
|
85
|
+
The earlier backoff, circuit breaker and 413 halving were removed by ruling
|
|
86
|
+
(R-retry, CONTRACT-R2 S1): every one of them resent requests the server had answered.
|
|
87
87
|
|
|
88
88
|
### Timestamps
|
|
89
89
|
|
|
@@ -100,21 +100,23 @@ different source. Never coerce an id numerically, in any language, at any layer.
|
|
|
100
100
|
|
|
101
101
|
### Delivery is at-least-once
|
|
102
102
|
|
|
103
|
-
Ingestion has no idempotency key.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
Ingestion has no idempotency key. Inside one request, payload items that share an
|
|
104
|
+
`event_id` are stored as one row: measured 2026-11-16 (INT-5415, INT-5410), an order
|
|
105
|
+
with two lines and one shared id stored one row, and with an id per line it stored two.
|
|
106
|
+
So every payload item carries its own `event_id`. Whether a resend of a request that
|
|
107
|
+
already landed is collapsed is not measured, so the SDK assumes it is not. That is why
|
|
108
|
+
nothing that may have landed is resent.
|
|
107
109
|
|
|
108
110
|
### close() is bounded
|
|
109
111
|
|
|
110
|
-
`close()` drains for at most 30 seconds, then
|
|
112
|
+
`close()` drains for at most 30 seconds, then drops, reports and logs how many events
|
|
111
113
|
it abandoned. Unbounded, a shutdown hook blocks for minutes against a failing
|
|
112
114
|
endpoint. `flush()` is **not** bounded — a caller who is not shutting down has not
|
|
113
115
|
asked to give up.
|
|
114
116
|
|
|
115
|
-
Enforce the deadline in two places, because one leaks: before starting
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
Enforce the deadline in two places, because one leaks: before starting the one resend
|
|
118
|
+
wait and at the top of each drain iteration (sends that succeed but are slow never
|
|
119
|
+
reach the wait check).
|
|
118
120
|
|
|
119
121
|
### opt-out gates buffered events too
|
|
120
122
|
|
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.1.0 — unreleased
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **`has_opted_out()`** (INT-5416), the inverse of `is_opted_in()`: true after
|
|
8
|
+
`opt_out()` and after `close()`. The public docs already name it.
|
|
9
|
+
|
|
10
|
+
### Changed — behaviour
|
|
11
|
+
|
|
12
|
+
- **A `datetime` or `date` inside `properties`, `user_attributes` or
|
|
13
|
+
`account_attributes` is sent as an ISO-8601 UTC string with milliseconds**
|
|
14
|
+
(INT-5418), `YYYY-MM-DDTHH:MM:SS.sssZ`, as the Swift, JS, Node and React Native SDKs
|
|
15
|
+
send it. Before, a `datetime` went out as epoch milliseconds and a `date` raised
|
|
16
|
+
`TypeError`. A naive `datetime` is read as UTC (it was read as local time); a `date`
|
|
17
|
+
is midnight UTC. The event `timestamp` option is unchanged and stays epoch
|
|
18
|
+
milliseconds.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- **`ecommerce.ordered()` gives each product line its own `eventId`** (INT-5415).
|
|
23
|
+
The lines shared one id, and the server kept only one line of a multi-product order.
|
|
24
|
+
|
|
25
|
+
## 3.0.0 — 2026-11-13
|
|
26
|
+
|
|
27
|
+
### Changed — breaking
|
|
28
|
+
|
|
29
|
+
- **Each request is sent once** (INT-7436). 503 and 429 get one resend after
|
|
30
|
+
`Retry-After` clamped to 1–60 s (1 s when absent); a wait over 5 s drops the batch
|
|
31
|
+
instead of sleeping. Every other answered status, 413 included, and a timeout after
|
|
32
|
+
the request was written are dropped and reported. A batch that never reached the
|
|
33
|
+
server stays queued for the next flush. The exponential backoff, the circuit breaker
|
|
34
|
+
and the 413 halving are gone. `IntemptApiError.retryable` is now true for 429 and 503
|
|
35
|
+
only; new `reached` and `timed_out` attributes say how a transport failure happened.
|
|
36
|
+
A pooled keep-alive socket the server already closed is not a lost batch: the
|
|
37
|
+
transport reconnects once at once and sends on the fresh socket.
|
|
38
|
+
- **A kept batch waits for the timer, and the queue cap evicts the oldest event**
|
|
39
|
+
(ruling R4). While a batch that never reached the server is kept, reaching `size`
|
|
40
|
+
no longer sends; the batch goes out at the next `flush_ms` tick or an explicit
|
|
41
|
+
`flush()`. At `max_queue` the oldest queued event is dropped and reported `dropped`
|
|
42
|
+
and the new event is queued (`track` returns True); before, the new event was refused.
|
|
43
|
+
- **Writes no longer raise for a delivery problem** (INT-7444). `track`, `track_batch`,
|
|
44
|
+
`identify`, `group`, `consent.grant/revoke` and the `ecommerce` methods return `bool`
|
|
45
|
+
(queued in batch mode, delivered in direct mode). A new `on_delivery_failure` option
|
|
46
|
+
receives a `DeliveryFailure` once per batch on its final outcome. `flush()` and
|
|
47
|
+
`close()` return `FlushResult(sent, failed)`. Code that caught `IntemptApiError`
|
|
48
|
+
around a write must read the return value or the listener instead. Bad arguments and
|
|
49
|
+
a closed client still raise; `recommend()` still raises.
|
|
50
|
+
- **`all_flags()` no longer records exposures** (INT-7456). It sends `exposure: false`,
|
|
51
|
+
so a bulk read does not count every key as seen; read the key you show with
|
|
52
|
+
`variation()`, or pass `all_flags(..., log_exposure=True)`. Needs the matching
|
|
53
|
+
audience-service change; until then the service ignores the field.
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
|
|
57
|
+
- **`on_flag_error` and public `variation_detail()`** (INT-7454). A failed evaluation
|
|
58
|
+
still returns the default, and now calls `on_flag_error(FlagError(key, kind, status))`
|
|
59
|
+
with `kind` one of `auth`, `bad_request`, `server`, `timeout`, `network`, `parse`.
|
|
60
|
+
`variation_detail()` returns `FlagDetail(value, reason, error)` with `reason="error"`
|
|
61
|
+
on a failure; a 200 with no choice stays `off`. 401/403 is logged at error level once
|
|
62
|
+
per client, naming the key prefix and `source_id`, then at debug.
|
|
63
|
+
- **`disable_exposure=True`** on `variation`, `variation_detail` and the typed variants
|
|
64
|
+
(INT-7456), for a read that does not display the value.
|
|
65
|
+
|
|
3
66
|
## 2.1.0 — unreleased
|
|
4
67
|
|
|
5
68
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: intempt
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.1.0
|
|
4
4
|
Summary: Intempt Python SDK — server-side. Data in, decisions out.
|
|
5
5
|
Project-URL: Homepage, https://intempt.com
|
|
6
6
|
Project-URL: Source, https://github.com/intempt/intempt-python
|
|
@@ -72,21 +72,27 @@ other short-lived processes.
|
|
|
72
72
|
| call | returns | endpoint |
|
|
73
73
|
| ---- | ------- | -------- |
|
|
74
74
|
| `Intempt(**config)` | client | — |
|
|
75
|
-
| `track(event, **options)` | `
|
|
76
|
-
| `track_batch(events)` | `
|
|
77
|
-
| `identify(**options)` | `
|
|
78
|
-
| `group(account_id=…, **options)` | `
|
|
79
|
-
| `consent.grant(**options)` | `
|
|
80
|
-
| `consent.revoke(**options)` | `
|
|
81
|
-
| `ecommerce.product_viewed(product_id=…, **ids)` | `
|
|
82
|
-
| `ecommerce.added_to_cart(product_id=…, quantity=…, **ids)` | `
|
|
83
|
-
| `ecommerce.ordered(products=[…], **ids)` | `
|
|
75
|
+
| `track(event, **options)` | `bool` | `POST …/track` |
|
|
76
|
+
| `track_batch(events)` | `bool` | `POST …/track`, chunked |
|
|
77
|
+
| `identify(**options)` | `bool` | `POST …/track` (reserved `Identify`) |
|
|
78
|
+
| `group(account_id=…, **options)` | `bool` | `POST …/track` (reserved `Identify`) |
|
|
79
|
+
| `consent.grant(**options)` | `bool` | `POST …/consents/data` |
|
|
80
|
+
| `consent.revoke(**options)` | `bool` | `POST …/consents/data` |
|
|
81
|
+
| `ecommerce.product_viewed(product_id=…, **ids)` | `bool` | `POST …/track` |
|
|
82
|
+
| `ecommerce.added_to_cart(product_id=…, quantity=…, **ids)` | `bool` | `POST …/track` |
|
|
83
|
+
| `ecommerce.ordered(products=[…], **ids)` | `bool` | `POST …/track` |
|
|
84
84
|
| `recommend(feed_id=…, fields=[…], **ids)` | `dict` | `POST …/feeds/{id}/data` |
|
|
85
|
-
| `opt_in()` / `opt_out()` / `is_opted_in()` | — | — |
|
|
86
|
-
| `flush()` / `close()` | `
|
|
85
|
+
| `opt_in()` / `opt_out()` / `is_opted_in()` / `has_opted_out()` | — | — |
|
|
86
|
+
| `flush()` / `close()` | `FlushResult(sent, failed)` | — |
|
|
87
87
|
| `set_config(**patch)` / `config` / `buffered` | — | — |
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
Writes (`track`, `track_batch`, `identify`, `group`, `consent.*`, `ecommerce.*`) return `bool`
|
|
90
|
+
— queued in batch mode, delivered in direct mode — and never raise for a delivery problem.
|
|
91
|
+
A failed send is reported once per batch to the `on_delivery_failure` callable you pass to
|
|
92
|
+
`Intempt(...)`, as a `DeliveryFailure(kind, event_count, event_ids, terminal, status,
|
|
93
|
+
retry_after)`. A bad argument or a closed client still raises `IntemptConfigError`, and
|
|
94
|
+
`recommend()` still raises `IntemptApiError`. The return values in the table above that say
|
|
95
|
+
`None` are `bool` for these write methods.
|
|
90
96
|
|
|
91
97
|
## Identifiers
|
|
92
98
|
|
|
@@ -126,43 +132,46 @@ intempt.flush() # send now
|
|
|
126
132
|
intempt.close() # drain and release
|
|
127
133
|
```
|
|
128
134
|
|
|
129
|
-
`flush()` and `close()` are safe to call when batching is off; they
|
|
135
|
+
`flush()` and `close()` are safe to call when batching is off; they return
|
|
136
|
+
`FlushResult(sent=0, failed=0)`. `close()` is this SDK's shutdown.
|
|
130
137
|
|
|
131
|
-
`close()` drains for at most 30 seconds, then
|
|
132
|
-
it gave up on. Without a ceiling a shutdown hook can block for minutes against a
|
|
138
|
+
`close()` drains for at most 30 seconds, then drops what is left, counts it as
|
|
139
|
+
`failed`, reports it as `dropped` and logs how many events it gave up on. Without a ceiling a shutdown hook can block for minutes against a
|
|
133
140
|
failing endpoint. `flush()` is **not** bounded: a caller who is not shutting down has
|
|
134
141
|
not asked to give up.
|
|
135
142
|
|
|
136
|
-
###
|
|
143
|
+
### Send policy (INT-7436)
|
|
144
|
+
|
|
145
|
+
Each request is sent once, in batch and direct mode alike.
|
|
137
146
|
|
|
138
147
|
| response | behaviour |
|
|
139
148
|
| -------- | --------- |
|
|
140
|
-
|
|
|
141
|
-
|
|
|
142
|
-
|
|
|
143
|
-
|
|
|
144
|
-
|
|
|
145
|
-
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
successful sends that filled it, doubling each time. One transient 413 costs
|
|
150
|
-
throughput for a while rather than forever.
|
|
149
|
+
| 2xx | sent |
|
|
150
|
+
| 503, 429 | resend once after `Retry-After` clamped to 1–60 s (1 s when absent); a wait over 5 s drops instead of sleeping |
|
|
151
|
+
| any other status (400, 401–404, 408, 413, 500, 502, 504, …) | drop and report |
|
|
152
|
+
| timeout or broken connection after the request was written | drop and report; the server may already have it |
|
|
153
|
+
| never reached the server (DNS, refused, connect timeout) | batch mode keeps the batch until the next timed flush (`flush_ms`) or an explicit `flush()`, and reaching `size` meanwhile sends nothing; direct mode drops and reports |
|
|
154
|
+
| a pooled keep-alive socket the server already closed | reconnect once at once and send on the fresh socket |
|
|
155
|
+
|
|
156
|
+
At `max_queue` the oldest queued event that no send is carrying is dropped and reported
|
|
157
|
+
`dropped`, and the new event is queued.
|
|
151
158
|
|
|
152
159
|
The buffer is in memory. A hard crash loses it.
|
|
153
160
|
|
|
154
|
-
**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
the
|
|
158
|
-
you would rather a failure surface to your code than be retried, and de-duplicate
|
|
159
|
-
downstream if exact counts matter.
|
|
161
|
+
**Ingestion has no idempotency key.** Payload items of one request that share an
|
|
162
|
+
`eventId` are stored as one row (measured, INT-5415), so each item gets its own id.
|
|
163
|
+
Whether a resend of a request that already landed is collapsed is not measured. That is why a request that may have landed (a timeout after the write) is
|
|
164
|
+
never resent: the SDK trades a possible loss, which it reports, for no duplicates.
|
|
160
165
|
|
|
161
166
|
## Timestamps
|
|
162
167
|
|
|
163
168
|
`timestamp` accepts a `datetime` or epoch milliseconds. A naive `datetime` is treated
|
|
164
169
|
as UTC, not local time.
|
|
165
170
|
|
|
171
|
+
A `datetime` or `date` inside `properties` or the attribute maps is sent as an ISO-8601
|
|
172
|
+
UTC string with milliseconds (`2026-01-01T09:30:05.123Z`), the same as the other SDKs.
|
|
173
|
+
Naive is UTC there too; a `date` is midnight UTC.
|
|
174
|
+
|
|
166
175
|
It **is** a backfill mechanism, between 2010 and 2040. The event store keeps your value
|
|
167
176
|
and records arrival separately, so the two never overwrite each other.
|
|
168
177
|
|
|
@@ -45,21 +45,27 @@ other short-lived processes.
|
|
|
45
45
|
| call | returns | endpoint |
|
|
46
46
|
| ---- | ------- | -------- |
|
|
47
47
|
| `Intempt(**config)` | client | — |
|
|
48
|
-
| `track(event, **options)` | `
|
|
49
|
-
| `track_batch(events)` | `
|
|
50
|
-
| `identify(**options)` | `
|
|
51
|
-
| `group(account_id=…, **options)` | `
|
|
52
|
-
| `consent.grant(**options)` | `
|
|
53
|
-
| `consent.revoke(**options)` | `
|
|
54
|
-
| `ecommerce.product_viewed(product_id=…, **ids)` | `
|
|
55
|
-
| `ecommerce.added_to_cart(product_id=…, quantity=…, **ids)` | `
|
|
56
|
-
| `ecommerce.ordered(products=[…], **ids)` | `
|
|
48
|
+
| `track(event, **options)` | `bool` | `POST …/track` |
|
|
49
|
+
| `track_batch(events)` | `bool` | `POST …/track`, chunked |
|
|
50
|
+
| `identify(**options)` | `bool` | `POST …/track` (reserved `Identify`) |
|
|
51
|
+
| `group(account_id=…, **options)` | `bool` | `POST …/track` (reserved `Identify`) |
|
|
52
|
+
| `consent.grant(**options)` | `bool` | `POST …/consents/data` |
|
|
53
|
+
| `consent.revoke(**options)` | `bool` | `POST …/consents/data` |
|
|
54
|
+
| `ecommerce.product_viewed(product_id=…, **ids)` | `bool` | `POST …/track` |
|
|
55
|
+
| `ecommerce.added_to_cart(product_id=…, quantity=…, **ids)` | `bool` | `POST …/track` |
|
|
56
|
+
| `ecommerce.ordered(products=[…], **ids)` | `bool` | `POST …/track` |
|
|
57
57
|
| `recommend(feed_id=…, fields=[…], **ids)` | `dict` | `POST …/feeds/{id}/data` |
|
|
58
|
-
| `opt_in()` / `opt_out()` / `is_opted_in()` | — | — |
|
|
59
|
-
| `flush()` / `close()` | `
|
|
58
|
+
| `opt_in()` / `opt_out()` / `is_opted_in()` / `has_opted_out()` | — | — |
|
|
59
|
+
| `flush()` / `close()` | `FlushResult(sent, failed)` | — |
|
|
60
60
|
| `set_config(**patch)` / `config` / `buffered` | — | — |
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
Writes (`track`, `track_batch`, `identify`, `group`, `consent.*`, `ecommerce.*`) return `bool`
|
|
63
|
+
— queued in batch mode, delivered in direct mode — and never raise for a delivery problem.
|
|
64
|
+
A failed send is reported once per batch to the `on_delivery_failure` callable you pass to
|
|
65
|
+
`Intempt(...)`, as a `DeliveryFailure(kind, event_count, event_ids, terminal, status,
|
|
66
|
+
retry_after)`. A bad argument or a closed client still raises `IntemptConfigError`, and
|
|
67
|
+
`recommend()` still raises `IntemptApiError`. The return values in the table above that say
|
|
68
|
+
`None` are `bool` for these write methods.
|
|
63
69
|
|
|
64
70
|
## Identifiers
|
|
65
71
|
|
|
@@ -99,43 +105,46 @@ intempt.flush() # send now
|
|
|
99
105
|
intempt.close() # drain and release
|
|
100
106
|
```
|
|
101
107
|
|
|
102
|
-
`flush()` and `close()` are safe to call when batching is off; they
|
|
108
|
+
`flush()` and `close()` are safe to call when batching is off; they return
|
|
109
|
+
`FlushResult(sent=0, failed=0)`. `close()` is this SDK's shutdown.
|
|
103
110
|
|
|
104
|
-
`close()` drains for at most 30 seconds, then
|
|
105
|
-
it gave up on. Without a ceiling a shutdown hook can block for minutes against a
|
|
111
|
+
`close()` drains for at most 30 seconds, then drops what is left, counts it as
|
|
112
|
+
`failed`, reports it as `dropped` and logs how many events it gave up on. Without a ceiling a shutdown hook can block for minutes against a
|
|
106
113
|
failing endpoint. `flush()` is **not** bounded: a caller who is not shutting down has
|
|
107
114
|
not asked to give up.
|
|
108
115
|
|
|
109
|
-
###
|
|
116
|
+
### Send policy (INT-7436)
|
|
117
|
+
|
|
118
|
+
Each request is sent once, in batch and direct mode alike.
|
|
110
119
|
|
|
111
120
|
| response | behaviour |
|
|
112
121
|
| -------- | --------- |
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
|
|
|
117
|
-
|
|
|
118
|
-
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
successful sends that filled it, doubling each time. One transient 413 costs
|
|
123
|
-
throughput for a while rather than forever.
|
|
122
|
+
| 2xx | sent |
|
|
123
|
+
| 503, 429 | resend once after `Retry-After` clamped to 1–60 s (1 s when absent); a wait over 5 s drops instead of sleeping |
|
|
124
|
+
| any other status (400, 401–404, 408, 413, 500, 502, 504, …) | drop and report |
|
|
125
|
+
| timeout or broken connection after the request was written | drop and report; the server may already have it |
|
|
126
|
+
| never reached the server (DNS, refused, connect timeout) | batch mode keeps the batch until the next timed flush (`flush_ms`) or an explicit `flush()`, and reaching `size` meanwhile sends nothing; direct mode drops and reports |
|
|
127
|
+
| a pooled keep-alive socket the server already closed | reconnect once at once and send on the fresh socket |
|
|
128
|
+
|
|
129
|
+
At `max_queue` the oldest queued event that no send is carrying is dropped and reported
|
|
130
|
+
`dropped`, and the new event is queued.
|
|
124
131
|
|
|
125
132
|
The buffer is in memory. A hard crash loses it.
|
|
126
133
|
|
|
127
|
-
**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
the
|
|
131
|
-
you would rather a failure surface to your code than be retried, and de-duplicate
|
|
132
|
-
downstream if exact counts matter.
|
|
134
|
+
**Ingestion has no idempotency key.** Payload items of one request that share an
|
|
135
|
+
`eventId` are stored as one row (measured, INT-5415), so each item gets its own id.
|
|
136
|
+
Whether a resend of a request that already landed is collapsed is not measured. That is why a request that may have landed (a timeout after the write) is
|
|
137
|
+
never resent: the SDK trades a possible loss, which it reports, for no duplicates.
|
|
133
138
|
|
|
134
139
|
## Timestamps
|
|
135
140
|
|
|
136
141
|
`timestamp` accepts a `datetime` or epoch milliseconds. A naive `datetime` is treated
|
|
137
142
|
as UTC, not local time.
|
|
138
143
|
|
|
144
|
+
A `datetime` or `date` inside `properties` or the attribute maps is sent as an ISO-8601
|
|
145
|
+
UTC string with milliseconds (`2026-01-01T09:30:05.123Z`), the same as the other SDKs.
|
|
146
|
+
Naive is UTC there too; a `date` is midnight UTC.
|
|
147
|
+
|
|
139
148
|
It **is** a backfill mechanism, between 2010 and 2040. The event store keeps your value
|
|
140
149
|
and records arrival separately, so the two never overwrite each other.
|
|
141
150
|
|
|
@@ -19,10 +19,10 @@ to this repo. Where the two disagree, the contract wins and this file is the bug
|
|
|
19
19
|
- **A wrong-typed value falls back; it is never coerced.** A flag configured as a string and read as
|
|
20
20
|
a boolean returns the caller's default, not `true`. Coercion makes a misconfiguration look like a
|
|
21
21
|
deliberate value.
|
|
22
|
-
- **`variationDetail` is
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
- **`variationDetail` is public** (Beso ruling R1, 2026-11-13, binding on all seven SDKs), with
|
|
23
|
+
`FlagDetail`, `FlagReason`, `disableExposure` and `onFlagError`. Its `reason` is narrow: `error`
|
|
24
|
+
when the evaluation failed, and `off` otherwise, a served value included, because the serving
|
|
25
|
+
response sends no reason. Do not derive a targeting reason the service did not send.
|
|
26
26
|
- **Evaluation is REMOTE only.** No local rule engine, no flag store to poll, and no hashing
|
|
27
27
|
utility: the server buckets, so no second implementation can disagree with it. `check-no-local-bucketing.mjs`
|
|
28
28
|
enforces this in CI and a new bucketing helper will fail the build.
|
|
@@ -54,9 +54,12 @@ one the second read of such a key returns nothing and every exposure lands in on
|
|
|
54
54
|
|
|
55
55
|
Two tiers, and they are not interchangeable: a configuration mistake surfaces when the config is
|
|
56
56
|
built, and an API failure carries the status, the body and any `Retry-After`. A transport failure
|
|
57
|
-
that never produced a response carries a **null** status
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
that never produced a response carries a **null** status, and `reached` says whether the request
|
|
58
|
+
left at all: only a request that never reached the server is safe to send again. One case looks
|
|
59
|
+
like a lost connection but is never-reached: a pooled keep-alive socket the server already closed
|
|
60
|
+
while idle. The transport reconnects once at once and sends on the fresh socket (ruling R5); a
|
|
61
|
+
connection lost on a fresh socket, or a timeout, after the write is dropped and never resent. `retryable` is
|
|
62
|
+
true for 429 and 503 alone, the statuses the SDK resends once (INT-7436).
|
|
60
63
|
|
|
61
64
|
## Wire shape
|
|
62
65
|
|
|
@@ -92,8 +95,10 @@ a reading of the service's security configuration to cite.
|
|
|
92
95
|
## Python specifics
|
|
93
96
|
|
|
94
97
|
- **Naming follows the language, not the contract's spelling.** The contract's `allFlags` is
|
|
95
|
-
`all_flags` here
|
|
96
|
-
|
|
98
|
+
`all_flags` here, `variationDetail` is `variation_detail` (public since INT-7454),
|
|
99
|
+
`onFlagError` is `on_flag_error`, `onDeliveryFailure` is `on_delivery_failure` and
|
|
100
|
+
`disableExposure` is `disable_exposure`; the shape is identical, the case is not. A contract
|
|
101
|
+
`shutdown()` is `close()` here, the name this SDK already had.
|
|
97
102
|
- **The mutation threshold is 70, not 85.** That is a measured decision, not an oversight: mutmut's
|
|
98
103
|
operator set produces a materially different denominator from Stryker's and Infection's, and 70 here
|
|
99
104
|
was the level at which surviving mutants were genuinely equivalent rather than untested. Raising it
|
|
@@ -12,8 +12,9 @@ code, and the whole file runs in about a second.
|
|
|
12
12
|
python examples/bare/send.py
|
|
13
13
|
|
|
14
14
|
Every call sends one request and returns when the server answers, so the events
|
|
15
|
-
are in the console by the time this exits.
|
|
16
|
-
|
|
15
|
+
are in the console by the time this exits. A write that fails does not raise: it
|
|
16
|
+
is reported to `on_delivery_failure`, which this sample turns into exit code 1.
|
|
17
|
+
Open Sources -> your source -> Live events and look for the user id printed at the end.
|
|
17
18
|
|
|
18
19
|
Copyright 2026 Intempt Technologies
|
|
19
20
|
Licensed under the Apache License, Version 2.0.
|
|
@@ -46,6 +47,7 @@ def main() -> int:
|
|
|
46
47
|
# Construction validates, so it gets the same handling as the calls below.
|
|
47
48
|
# Leaving it outside the try turned a blank INTEMPT_ORG into a traceback
|
|
48
49
|
# instead of the one-line message this prints for every other bad argument.
|
|
50
|
+
failures = []
|
|
49
51
|
try:
|
|
50
52
|
client = Intempt(
|
|
51
53
|
org=os.environ["INTEMPT_ORG"],
|
|
@@ -54,6 +56,7 @@ def main() -> int:
|
|
|
54
56
|
source_id=os.environ.get("INTEMPT_SOURCE_ID"),
|
|
55
57
|
host=os.environ.get("INTEMPT_HOST") or "api.intempt.com",
|
|
56
58
|
scheme=os.environ.get("INTEMPT_SCHEME") or "https",
|
|
59
|
+
on_delivery_failure=failures.append,
|
|
57
60
|
)
|
|
58
61
|
except IntemptConfigError as error:
|
|
59
62
|
print(f"bad arguments: {error}", file=sys.stderr)
|
|
@@ -134,10 +137,18 @@ def main() -> int:
|
|
|
134
137
|
print(f"bad arguments: {error}", file=sys.stderr)
|
|
135
138
|
return 2
|
|
136
139
|
except IntemptApiError as error:
|
|
137
|
-
print(f"API error: status={error.status}
|
|
138
|
-
print(f"body: {error.body}", file=sys.stderr)
|
|
140
|
+
print(f"API error: status={error.status} body: {error.body}", file=sys.stderr)
|
|
139
141
|
return 1
|
|
140
142
|
|
|
143
|
+
if failures:
|
|
144
|
+
for failure in failures:
|
|
145
|
+
print(
|
|
146
|
+
f"delivery failed: kind={failure.kind} status={failure.status} "
|
|
147
|
+
f"events={failure.event_count} terminal={failure.terminal}",
|
|
148
|
+
file=sys.stderr,
|
|
149
|
+
)
|
|
150
|
+
return 1
|
|
151
|
+
|
|
141
152
|
print(f"sent. look for user id {user_id!r} in Sources -> Live events.")
|
|
142
153
|
return 0
|
|
143
154
|
|
|
@@ -117,16 +117,18 @@ class Handler(BaseHTTPRequestHandler):
|
|
|
117
117
|
return self._reply(201, {"ok": True})
|
|
118
118
|
|
|
119
119
|
if route == "/forget":
|
|
120
|
-
#
|
|
121
|
-
#
|
|
122
|
-
intempt.consent.revoke(user_id=user, reason="user requested deletion")
|
|
120
|
+
# A withdrawal is a privacy record: revoke() reports a failure as
|
|
121
|
+
# False rather than raising, so the page must not say it is done.
|
|
122
|
+
if not intempt.consent.revoke(user_id=user, reason="user requested deletion"):
|
|
123
|
+
return self._reply(502, {"error": "consent withdrawal not recorded"})
|
|
123
124
|
return self._reply(202, {"ok": True})
|
|
124
125
|
|
|
125
126
|
return self._reply(404, {"error": "no such route"})
|
|
126
127
|
|
|
127
128
|
except IntemptApiError as exc:
|
|
128
|
-
#
|
|
129
|
-
#
|
|
129
|
+
# Writes no longer raise on a failed send: they are reported to
|
|
130
|
+
# on_delivery_failure. What still reaches here is a call that
|
|
131
|
+
# answers with data, so a real app decides whether to fail the page.
|
|
130
132
|
log.error("intempt rejected the write: %s", exc)
|
|
131
133
|
return self._reply(502, {"error": "analytics write failed"})
|
|
132
134
|
except ValueError as exc:
|
|
@@ -43,7 +43,7 @@ from pathlib import Path
|
|
|
43
43
|
|
|
44
44
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))
|
|
45
45
|
|
|
46
|
-
from intempt import BatchOptions, Intempt, IntemptApiError # noqa: E402
|
|
46
|
+
from intempt import BatchOptions, DeliveryFailure, Intempt, IntemptApiError # noqa: E402
|
|
47
47
|
|
|
48
48
|
# --- .env.local -------------------------------------------------------------
|
|
49
49
|
|
|
@@ -115,6 +115,10 @@ for name, value, used_by in [
|
|
|
115
115
|
print(f" {'have' if value else 'MISS'} {name:<22} {used_by}")
|
|
116
116
|
print(" " + "-" * 76 + "\n")
|
|
117
117
|
|
|
118
|
+
# Writes report a refused or lost delivery through their return value and this listener, not
|
|
119
|
+
# by raising (INT-7444), so a step that merely did not raise has proved nothing.
|
|
120
|
+
failures: list[DeliveryFailure] = []
|
|
121
|
+
|
|
118
122
|
client = Intempt(
|
|
119
123
|
org=ORG,
|
|
120
124
|
project=PROJECT,
|
|
@@ -122,8 +126,21 @@ client = Intempt(
|
|
|
122
126
|
source_id=SOURCE_ID,
|
|
123
127
|
host=HOST,
|
|
124
128
|
scheme=SCHEME,
|
|
129
|
+
on_delivery_failure=failures.append,
|
|
125
130
|
)
|
|
126
131
|
|
|
132
|
+
|
|
133
|
+
class WriteFailed(Exception):
|
|
134
|
+
pass
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def describe(failure: DeliveryFailure | None) -> str:
|
|
138
|
+
if failure is None:
|
|
139
|
+
return "no delivery failure was reported"
|
|
140
|
+
status = failure.status if failure.status is not None else "no status"
|
|
141
|
+
return f"{failure.kind} {status}"
|
|
142
|
+
|
|
143
|
+
|
|
127
144
|
# --- harness ----------------------------------------------------------------
|
|
128
145
|
|
|
129
146
|
results: list[dict[str, object]] = []
|
|
@@ -131,8 +148,11 @@ results: list[dict[str, object]] = []
|
|
|
131
148
|
|
|
132
149
|
def step(name: str, fn) -> None:
|
|
133
150
|
started = time.monotonic()
|
|
151
|
+
failures.clear()
|
|
134
152
|
try:
|
|
135
153
|
value = fn()
|
|
154
|
+
if value is False:
|
|
155
|
+
raise WriteFailed(f"returned False: {describe(failures[-1] if failures else None)}")
|
|
136
156
|
ms = int((time.monotonic() - started) * 1000)
|
|
137
157
|
note = "2xx" if value is None else str(value)[:60]
|
|
138
158
|
results.append({"name": name, "state": "PASS", "ms": ms, "note": note})
|
|
@@ -265,6 +285,7 @@ else:
|
|
|
265
285
|
|
|
266
286
|
|
|
267
287
|
def buffered() -> str:
|
|
288
|
+
buffered_failures: list[DeliveryFailure] = []
|
|
268
289
|
buffered_client = Intempt(
|
|
269
290
|
org=ORG,
|
|
270
291
|
project=PROJECT,
|
|
@@ -273,11 +294,19 @@ def buffered() -> str:
|
|
|
273
294
|
host=HOST,
|
|
274
295
|
scheme=SCHEME,
|
|
275
296
|
batch=BatchOptions(size=50, flush_ms=60_000, max_queue=1_000),
|
|
297
|
+
on_delivery_failure=buffered_failures.append,
|
|
276
298
|
)
|
|
277
299
|
try:
|
|
278
|
-
|
|
300
|
+
queued = [
|
|
279
301
|
buffered_client.track("sdk_e2e_buffered", user_id=user_id, properties={"i": index})
|
|
280
|
-
|
|
302
|
+
for index in range(5)
|
|
303
|
+
]
|
|
304
|
+
if not all(queued):
|
|
305
|
+
raise WriteFailed(f"only {sum(queued)} of 5 events were queued")
|
|
306
|
+
result = buffered_client.flush()
|
|
307
|
+
if result.sent != 5 or result.failed:
|
|
308
|
+
last = describe(buffered_failures[-1] if buffered_failures else None)
|
|
309
|
+
raise WriteFailed(f"flush sent {result.sent}, failed {result.failed}: {last}")
|
|
281
310
|
return "5 events, 1 request"
|
|
282
311
|
finally:
|
|
283
312
|
buffered_client.close()
|