intempt 2.0.0__tar.gz → 3.0.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.
Files changed (52) hide show
  1. intempt-3.0.0/.github/workflows/autopr.yaml +30 -0
  2. intempt-3.0.0/.github/workflows/blu-bot-pipeline-caller.yml +18 -0
  3. {intempt-2.0.0 → intempt-3.0.0}/.github/workflows/e2e.yml +2 -2
  4. intempt-3.0.0/.github/workflows/ff-merge.yml +15 -0
  5. {intempt-2.0.0 → intempt-3.0.0}/.github/workflows/release.yml +2 -2
  6. {intempt-2.0.0 → intempt-3.0.0}/.github/workflows/tests.yml +6 -6
  7. {intempt-2.0.0 → intempt-3.0.0}/ARCHITECTURE.md +26 -27
  8. {intempt-2.0.0 → intempt-3.0.0}/CHANGELOG.md +65 -0
  9. {intempt-2.0.0 → intempt-3.0.0}/PKG-INFO +39 -34
  10. {intempt-2.0.0 → intempt-3.0.0}/README.md +38 -33
  11. {intempt-2.0.0 → intempt-3.0.0}/docs/CONVENTIONS.md +14 -9
  12. {intempt-2.0.0 → intempt-3.0.0}/examples/bare/send.py +15 -4
  13. {intempt-2.0.0 → intempt-3.0.0}/examples/basic/app.py +7 -5
  14. {intempt-2.0.0 → intempt-3.0.0}/scripts/e2e.py +32 -3
  15. {intempt-2.0.0 → intempt-3.0.0}/src/intempt/__init__.py +8 -2
  16. intempt-3.0.0/src/intempt/_buffer.py +297 -0
  17. {intempt-2.0.0 → intempt-3.0.0}/src/intempt/_client.py +248 -99
  18. {intempt-2.0.0 → intempt-3.0.0}/src/intempt/_config.py +38 -0
  19. intempt-3.0.0/src/intempt/_delivery.py +137 -0
  20. {intempt-2.0.0 → intempt-3.0.0}/src/intempt/_errors.py +12 -7
  21. {intempt-2.0.0 → intempt-3.0.0}/src/intempt/_flags.py +15 -4
  22. {intempt-2.0.0 → intempt-3.0.0}/src/intempt/_transport.py +43 -7
  23. {intempt-2.0.0 → intempt-3.0.0}/tests/conftest.py +23 -1
  24. {intempt-2.0.0 → intempt-3.0.0}/tests/test_bare_sample.py +7 -3
  25. intempt-3.0.0/tests/test_buffer.py +453 -0
  26. {intempt-2.0.0 → intempt-3.0.0}/tests/test_client.py +46 -6
  27. {intempt-2.0.0 → intempt-3.0.0}/tests/test_config.py +30 -0
  28. intempt-3.0.0/tests/test_delivery_failure.py +626 -0
  29. intempt-3.0.0/tests/test_e2e_script.py +68 -0
  30. {intempt-2.0.0 → intempt-3.0.0}/tests/test_example_app.py +10 -1
  31. {intempt-2.0.0 → intempt-3.0.0}/tests/test_flags.py +260 -2
  32. intempt-3.0.0/tests/test_thresholds.py +144 -0
  33. intempt-3.0.0/tests/test_transport.py +390 -0
  34. intempt-2.0.0/.github/CODEOWNERS +0 -17
  35. intempt-2.0.0/src/intempt/_buffer.py +0 -330
  36. intempt-2.0.0/tests/test_buffer.py +0 -485
  37. intempt-2.0.0/tests/test_thresholds.py +0 -393
  38. intempt-2.0.0/tests/test_transport.py +0 -197
  39. {intempt-2.0.0 → intempt-3.0.0}/.gitignore +0 -0
  40. {intempt-2.0.0 → intempt-3.0.0}/LICENSE +0 -0
  41. {intempt-2.0.0 → intempt-3.0.0}/NOTICE +0 -0
  42. {intempt-2.0.0 → intempt-3.0.0}/docs/TESTING.md +0 -0
  43. {intempt-2.0.0 → intempt-3.0.0}/examples/README.md +0 -0
  44. {intempt-2.0.0 → intempt-3.0.0}/pyproject.toml +0 -0
  45. {intempt-2.0.0 → intempt-3.0.0}/scripts/check-no-local-bucketing.mjs +0 -0
  46. {intempt-2.0.0 → intempt-3.0.0}/scripts/mutation_gate.py +0 -0
  47. {intempt-2.0.0 → intempt-3.0.0}/scripts/no-local-bucketing-allow.json +0 -0
  48. {intempt-2.0.0 → intempt-3.0.0}/src/intempt/_util.py +0 -0
  49. {intempt-2.0.0 → intempt-3.0.0}/tests/__init__.py +0 -0
  50. {intempt-2.0.0 → intempt-3.0.0}/tests/test_bucketing_guard.py +0 -0
  51. {intempt-2.0.0 → intempt-3.0.0}/tests/test_credential_guard.py +0 -0
  52. {intempt-2.0.0 → intempt-3.0.0}/tests/test_messages.py +0 -0
@@ -0,0 +1,30 @@
1
+ name: Create Pull Request from Staging to Main
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - staging
7
+
8
+ jobs:
9
+ create_pr:
10
+ runs-on: intempt-ubuntu-github-runner
11
+ steps:
12
+ - name: Checkout code
13
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
14
+ with:
15
+ fetch-depth: 0
16
+
17
+ - name: Run the Action
18
+ uses: devops-infra/action-pull-request@e66e2ba93519dc63b9884a26e620e2fd0cffab2c # v0.5.5
19
+ with:
20
+ github_token: ${{ secrets.GITHUB_TOKEN }}
21
+ source_branch: staging
22
+ target_branch: main
23
+ title: 'Merge Staging into Main'
24
+ body: 'Automatically created pull request to merge changes from staging into main.'
25
+ reviewer: ${{ vars.REVIEWERS }}
26
+ assignee: ${{ vars.REVIEWERS }}
27
+ draft: false
28
+ get_diff: true
29
+ ignore_users: "dependabot"
30
+ allow_no_diff: false
@@ -0,0 +1,18 @@
1
+ name: blu-bot-pipeline
2
+
3
+ on:
4
+ pull_request_target:
5
+ types: [labeled]
6
+
7
+ concurrency:
8
+ group: blu-bot-pipeline-${{ github.repository }}-${{ github.event.pull_request.number }}
9
+
10
+ jobs:
11
+ pipeline:
12
+ if: github.event.label.name == 'admin-release'
13
+ permissions:
14
+ contents: read
15
+ pull-requests: write
16
+ uses: intempt/.github/.github/workflows/blu-bot-pipeline.yml@main
17
+ secrets:
18
+ BLU_BOT_PRIVATE_KEY: ${{ secrets.BLU_BOT_PRIVATE_KEY }}
@@ -36,7 +36,7 @@ permissions:
36
36
 
37
37
  jobs:
38
38
  e2e:
39
- runs-on: ubuntu-latest
39
+ runs-on: intempt-ubuntu-github-runner
40
40
  steps:
41
41
  - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
42
42
 
@@ -73,4 +73,4 @@ jobs:
73
73
  INTEMPT_E2E_FEED_ID: ${{ secrets.INTEMPT_E2E_FEED_ID }}
74
74
  INTEMPT_E2E_FEED_FIELDS: ${{ secrets.INTEMPT_E2E_FEED_FIELDS }}
75
75
  INTEMPT_E2E_PRODUCT_ID: ${{ secrets.INTEMPT_E2E_PRODUCT_ID }}
76
- run: python scripts/e2e.py
76
+ run: python scripts/e2e.py
@@ -0,0 +1,15 @@
1
+ name: ff-merge
2
+
3
+ on:
4
+ pull_request_target:
5
+ types: [labeled]
6
+
7
+ concurrency:
8
+ group: ff-merge-${{ github.repository }}
9
+
10
+ jobs:
11
+ ff-merge:
12
+ if: github.event.label.name == 'ff-merge'
13
+ uses: intempt/.github/.github/workflows/ff-merge.yml@main
14
+ secrets:
15
+ FF_BOT_PRIVATE_KEY: ${{ secrets.FF_BOT_PRIVATE_KEY }}
@@ -28,7 +28,7 @@ permissions:
28
28
 
29
29
  jobs:
30
30
  publish:
31
- runs-on: ubuntu-latest
31
+ runs-on: intempt-ubuntu-github-runner
32
32
  environment: pypi
33
33
  permissions:
34
34
  contents: write # create the GitHub Release
@@ -77,4 +77,4 @@ jobs:
77
77
  run: |
78
78
  gh release create "$GITHUB_REF_NAME" \
79
79
  --title "$GITHUB_REF_NAME" \
80
- --generate-notes
80
+ --generate-notes
@@ -15,10 +15,10 @@ jobs:
15
15
  # internally consistent. Runs without install so it cannot be skipped.
16
16
  bucketing:
17
17
  name: Server-only bucketing
18
- runs-on: ubuntu-latest
18
+ runs-on: intempt-ubuntu-github-runner
19
19
  steps:
20
- - uses: actions/checkout@v4
21
- - uses: actions/setup-node@v4
20
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
21
+ - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
22
22
  with:
23
23
  node-version: 22
24
24
  - name: No SDK derives buckets locally (R36)
@@ -27,7 +27,7 @@ jobs:
27
27
  GUARD_SRC: src
28
28
 
29
29
  test:
30
- runs-on: ubuntu-latest
30
+ runs-on: intempt-ubuntu-github-runner
31
31
  strategy:
32
32
  fail-fast: false
33
33
  matrix:
@@ -60,7 +60,7 @@ jobs:
60
60
  #
61
61
  # 3.12 specifically: mutmut needs libcst, and libcst has no prebuilt wheel
62
62
  # for 3.14 yet, so it tries to compile Rust and fails.
63
- runs-on: ubuntu-latest
63
+ runs-on: intempt-ubuntu-github-runner
64
64
  steps:
65
65
  - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
66
66
  - uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
@@ -94,4 +94,4 @@ jobs:
94
94
  with:
95
95
  name: mutation-report
96
96
  path: mutants/
97
- retention-days: 14
97
+ retention-days: 14
@@ -58,32 +58,32 @@ path is `…/track` rather than `…/sources/{id}/track`.
58
58
 
59
59
  ## Delivery guarantees
60
60
 
61
- ### Errors surface. Nothing is swallowed
61
+ ### Failed sends are reported, not raised (INT-7444)
62
62
 
63
- Every method raises/rejects on failure. No callback-swallow, no silent discard. This
64
- is the single biggest departure from mixpanel-node.
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
- ### Retry policy
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
- | 413, batch > 1 | halve the batch width, retry |
71
- | 413, batch = 1 | drop the event, log it, return the width to full |
72
- | 429 | honour `Retry-After`, else exponential backoff |
73
- | 5xx, 408, timeout | exponential backoff, floored at 100ms, capped at 10 min |
74
- | other 4xx | drop the batch, log status and body |
75
- | 5 consecutive failures | stop batching, report how many events are stranded |
76
- | 3 consecutive 413 drops | say the gateway body limit is the likely cause, once |
77
-
78
- Two width rules that are easy to get wrong, and were:
79
-
80
- 1. **A reduced width must recover.** Compare successes against the *current* width,
81
- not the full width — `batch` is sliced to the current width, so a comparison
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
 
@@ -102,19 +102,18 @@ different source. Never coerce an id numerically, in any language, at any layer.
102
102
 
103
103
  Ingestion has no idempotency key. `event_id` travels in the payload but is not a
104
104
  column in the events table, and the table is a plain `MergeTree` — nothing collapses
105
- duplicates. A retry after a lost response therefore duplicates rows. Say so in the
106
- README rather than letting callers infer exactly-once from the retry table.
105
+ duplicates. That is why nothing that may have landed is resent.
107
106
 
108
107
  ### close() is bounded
109
108
 
110
- `close()` drains for at most 30 seconds, then stops retrying and logs how many events
109
+ `close()` drains for at most 30 seconds, then drops, reports and logs how many events
111
110
  it abandoned. Unbounded, a shutdown hook blocks for minutes against a failing
112
111
  endpoint. `flush()` is **not** bounded — a caller who is not shutting down has not
113
112
  asked to give up.
114
113
 
115
- Enforce the deadline in two places, because one leaks: before starting a backoff (the
116
- first wait alone can exceed the whole budget) and at the top of each drain iteration
117
- (sends that succeed but are slow never reach the backoff check).
114
+ Enforce the deadline in two places, because one leaks: before starting the one resend
115
+ wait and at the top of each drain iteration (sends that succeed but are slow never
116
+ reach the wait check).
118
117
 
119
118
  ### opt-out gates buffered events too
120
119
 
@@ -1,5 +1,70 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.0 — unreleased
4
+
5
+ ### Changed — breaking
6
+
7
+ - **Each request is sent once** (INT-7436). 503 and 429 get one resend after
8
+ `Retry-After` clamped to 1–60 s (1 s when absent); a wait over 5 s drops the batch
9
+ instead of sleeping. Every other answered status, 413 included, and a timeout after
10
+ the request was written are dropped and reported. A batch that never reached the
11
+ server stays queued for the next flush. The exponential backoff, the circuit breaker
12
+ and the 413 halving are gone. `IntemptApiError.retryable` is now true for 429 and 503
13
+ only; new `reached` and `timed_out` attributes say how a transport failure happened.
14
+ A pooled keep-alive socket the server already closed is not a lost batch: the
15
+ transport reconnects once at once and sends on the fresh socket.
16
+ - **A kept batch waits for the timer, and the queue cap evicts the oldest event**
17
+ (ruling R4). While a batch that never reached the server is kept, reaching `size`
18
+ no longer sends; the batch goes out at the next `flush_ms` tick or an explicit
19
+ `flush()`. At `max_queue` the oldest queued event is dropped and reported `dropped`
20
+ and the new event is queued (`track` returns True); before, the new event was refused.
21
+ - **Writes no longer raise for a delivery problem** (INT-7444). `track`, `track_batch`,
22
+ `identify`, `group`, `consent.grant/revoke` and the `ecommerce` methods return `bool`
23
+ (queued in batch mode, delivered in direct mode). A new `on_delivery_failure` option
24
+ receives a `DeliveryFailure` once per batch on its final outcome. `flush()` and
25
+ `close()` return `FlushResult(sent, failed)`. Code that caught `IntemptApiError`
26
+ around a write must read the return value or the listener instead. Bad arguments and
27
+ a closed client still raise; `recommend()` still raises.
28
+ - **`all_flags()` no longer records exposures** (INT-7456). It sends `exposure: false`,
29
+ so a bulk read does not count every key as seen; read the key you show with
30
+ `variation()`, or pass `all_flags(..., log_exposure=True)`. Needs the matching
31
+ audience-service change; until then the service ignores the field.
32
+
33
+ ### Added
34
+
35
+ - **`on_flag_error` and public `variation_detail()`** (INT-7454). A failed evaluation
36
+ still returns the default, and now calls `on_flag_error(FlagError(key, kind, status))`
37
+ with `kind` one of `auth`, `bad_request`, `server`, `timeout`, `network`, `parse`.
38
+ `variation_detail()` returns `FlagDetail(value, reason, error)` with `reason="error"`
39
+ on a failure; a 200 with no choice stays `off`. 401/403 is logged at error level once
40
+ per client, naming the key prefix and `source_id`, then at debug.
41
+ - **`disable_exposure=True`** on `variation`, `variation_detail` and the typed variants
42
+ (INT-7456), for a read that does not display the value.
43
+
44
+ ## 2.1.0 — unreleased
45
+
46
+ ### Changed
47
+
48
+ - **`source_id` is validated at init** (INT-7455). It must be a positive 64-bit
49
+ integer as a string of digits (`^[1-9][0-9]{0,18}$`, at most
50
+ 9223372036854775807), which is what the API parses. A value such as `"abc"`,
51
+ `"0"` or a 20-digit id used to pass init and then fail every track and consent
52
+ call; it now raises.
53
+ - **Consent is sent while opted out** (INT-7437, ruling D-5). After `opt_out()`
54
+ consent records were dropped silently, so a person who had opted out could not
55
+ withdraw consent. Grant and revoke are now sent regardless of opt-out, as the
56
+ client SDKs do; tracking writes stay suppressed.
57
+ - **A flag's detail reason no longer reads `reason` off the choose response**
58
+ (INT-7457). choose-api never sends one; the reason is the fixed `UNANSWERED`,
59
+ as intempt-php already reports. No public effect.
60
+
61
+ ### Fixed
62
+
63
+ - **Buffer drop diagnostics no longer raise `KeyError` from a stdlib logger**
64
+ (INT-7440). They passed `extra={"name": ...}`, a reserved `LogRecord` key, so
65
+ with ERROR enabled (the default) `track()` on a stopped buffer or full queue,
66
+ and `flush()` on a single-event 413, raised. The key is now `event_name`.
67
+
3
68
  ## 2.0.0 — 2026-09-03
4
69
 
5
70
  ### Removed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: intempt
3
- Version: 2.0.0
3
+ Version: 3.0.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)` | `None` | `POST …/track` |
76
- | `track_batch(events)` | `None` | `POST …/track`, chunked |
77
- | `identify(**options)` | `None` | `POST …/track` (reserved `Identify`) |
78
- | `group(account_id=…, **options)` | `None` | `POST …/track` (reserved `Identify`) |
79
- | `consent.grant(**options)` | `None` | `POST …/consents/data` |
80
- | `consent.revoke(**options)` | `None` | `POST …/consents/data` |
81
- | `ecommerce.product_viewed(product_id=…, **ids)` | `None` | `POST …/track` |
82
- | `ecommerce.added_to_cart(product_id=…, quantity=…, **ids)` | `None` | `POST …/track` |
83
- | `ecommerce.ordered(products=[…], **ids)` | `None` | `POST …/track` |
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
85
  | `opt_in()` / `opt_out()` / `is_opted_in()` | — | — |
86
- | `flush()` / `close()` | `None` | — |
86
+ | `flush()` / `close()` | `FlushResult(sent, failed)` | — |
87
87
  | `set_config(**patch)` / `config` / `buffered` | — | — |
88
88
 
89
- Every method raises on failure. Nothing is swallowed.
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,37 +132,36 @@ 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 do nothing.
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 stops retrying and logs how many events
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
- ### Retry policy
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
- | 413, batch > 1 | halve the batch size, retry |
141
- | 413, batch = 1 | drop the event, log it, return the width to full |
142
- | 429 | honour `Retry-After`, else exponential backoff |
143
- | 5xx, 408, timeout | exponential backoff, floored at 100ms, capped at 10 min |
144
- | other 4xx | drop the batch, log the status and body |
145
- | 5 consecutive failures | stop batching and say how many events are stranded |
146
- | 3 consecutive 413 drops | say the gateway body limit is the likely cause, once |
147
-
148
- A 413 halves the width, and the width only widens again after ten consecutive
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
- **Delivery is at-least-once, not exactly-once.** A retry after a lost response
155
- re-sends events the server may already have stored, and ingestion has no idempotency
156
- key — `eventId` travels in the payload but is not a column in the events table, and
157
- the table is a plain `MergeTree`, so nothing collapses duplicates. Set `batch=None` if
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** — `eventId` travels in the payload but is not a
162
+ column in the events table, and the table is a plain `MergeTree`, so nothing collapses
163
+ duplicates. 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
 
@@ -179,7 +184,7 @@ like it just happened. The reverse mistake fails loudly.
179
184
  ## Opting out
180
185
 
181
186
  ```python
182
- intempt.opt_out() # suppresses track, batch, commerce and consent
187
+ intempt.opt_out() # suppresses track, batch and commerce; consent is still sent
183
188
  intempt.opt_in()
184
189
  ```
185
190
 
@@ -45,21 +45,27 @@ other short-lived processes.
45
45
  | call | returns | endpoint |
46
46
  | ---- | ------- | -------- |
47
47
  | `Intempt(**config)` | client | — |
48
- | `track(event, **options)` | `None` | `POST …/track` |
49
- | `track_batch(events)` | `None` | `POST …/track`, chunked |
50
- | `identify(**options)` | `None` | `POST …/track` (reserved `Identify`) |
51
- | `group(account_id=…, **options)` | `None` | `POST …/track` (reserved `Identify`) |
52
- | `consent.grant(**options)` | `None` | `POST …/consents/data` |
53
- | `consent.revoke(**options)` | `None` | `POST …/consents/data` |
54
- | `ecommerce.product_viewed(product_id=…, **ids)` | `None` | `POST …/track` |
55
- | `ecommerce.added_to_cart(product_id=…, quantity=…, **ids)` | `None` | `POST …/track` |
56
- | `ecommerce.ordered(products=[…], **ids)` | `None` | `POST …/track` |
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
58
  | `opt_in()` / `opt_out()` / `is_opted_in()` | — | — |
59
- | `flush()` / `close()` | `None` | — |
59
+ | `flush()` / `close()` | `FlushResult(sent, failed)` | — |
60
60
  | `set_config(**patch)` / `config` / `buffered` | — | — |
61
61
 
62
- Every method raises on failure. Nothing is swallowed.
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,37 +105,36 @@ 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 do nothing.
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 stops retrying and logs how many events
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
- ### Retry policy
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
- | 413, batch > 1 | halve the batch size, retry |
114
- | 413, batch = 1 | drop the event, log it, return the width to full |
115
- | 429 | honour `Retry-After`, else exponential backoff |
116
- | 5xx, 408, timeout | exponential backoff, floored at 100ms, capped at 10 min |
117
- | other 4xx | drop the batch, log the status and body |
118
- | 5 consecutive failures | stop batching and say how many events are stranded |
119
- | 3 consecutive 413 drops | say the gateway body limit is the likely cause, once |
120
-
121
- A 413 halves the width, and the width only widens again after ten consecutive
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
- **Delivery is at-least-once, not exactly-once.** A retry after a lost response
128
- re-sends events the server may already have stored, and ingestion has no idempotency
129
- key — `eventId` travels in the payload but is not a column in the events table, and
130
- the table is a plain `MergeTree`, so nothing collapses duplicates. Set `batch=None` if
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** — `eventId` travels in the payload but is not a
135
+ column in the events table, and the table is a plain `MergeTree`, so nothing collapses
136
+ duplicates. 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
 
@@ -152,7 +157,7 @@ like it just happened. The reverse mistake fails loudly.
152
157
  ## Opting out
153
158
 
154
159
  ```python
155
- intempt.opt_out() # suppresses track, batch, commerce and consent
160
+ intempt.opt_out() # suppresses track, batch and commerce; consent is still sent
156
161
  intempt.opt_in()
157
162
  ```
158
163
 
@@ -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 NOT exposed.** It would carry a reason, and the serving response does not
23
- send one — so it could only report "off" for a person who was in fact targeted and served, which
24
- is the single thing such a method exists to tell you. It stays internal until the platform sends
25
- a reason. Do not re-add it, and do not document it.
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 — read as retryable, because a request
58
- that never arrived may well arrive next time, whereas a 400 fails identically however often it is
59
- repeated.
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 and `variationDetail` is `_variation_detail`; the shape is identical, the case is
96
- not. A leading underscore is how this SDK expresses "withheld".
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. Open Sources -> your source -> Live
16
- events and look for the user id printed at the end.
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} retryable={error.retryable}", file=sys.stderr)
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
- # Revoking consent is a write like any other, and it is gated by
121
- # opt-out the same way.
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
- # Every method raises. Nothing is swallowed, so a real app decides
129
- # here whether the failure should reach the customer.
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: