intempt 3.0.0__tar.gz → 4.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.
- intempt-4.0.0/.claude/lane.json +1 -0
- {intempt-3.0.0 → intempt-4.0.0}/.github/workflows/tests.yml +8 -0
- {intempt-3.0.0 → intempt-4.0.0}/ARCHITECTURE.md +18 -9
- {intempt-3.0.0 → intempt-4.0.0}/CHANGELOG.md +105 -1
- {intempt-3.0.0 → intempt-4.0.0}/PKG-INFO +33 -9
- {intempt-3.0.0 → intempt-4.0.0}/README.md +32 -8
- intempt-4.0.0/docs/CONVENTIONS.md +98 -0
- {intempt-3.0.0 → intempt-4.0.0}/scripts/mutation_gate.py +16 -2
- intempt-4.0.0/src/intempt/__init__.py +83 -0
- {intempt-3.0.0 → intempt-4.0.0}/src/intempt/_buffer.py +62 -4
- intempt-4.0.0/src/intempt/_choose.py +175 -0
- {intempt-3.0.0 → intempt-4.0.0}/src/intempt/_client.py +70 -263
- {intempt-3.0.0 → intempt-4.0.0}/src/intempt/_config.py +17 -9
- {intempt-3.0.0 → intempt-4.0.0}/src/intempt/_delivery.py +1 -1
- intempt-4.0.0/src/intempt/_flag_stream.py +171 -0
- intempt-4.0.0/src/intempt/_flag_surface.py +137 -0
- intempt-4.0.0/src/intempt/_flags.py +727 -0
- intempt-4.0.0/src/intempt/_flags_client.py +68 -0
- intempt-4.0.0/src/intempt/_transport.py +431 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/conftest.py +148 -5
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_buffer.py +267 -1
- intempt-4.0.0/tests/test_choose.py +213 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_client.py +22 -4
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_delivery_failure.py +4 -2
- intempt-4.0.0/tests/test_flag_cache.py +520 -0
- intempt-4.0.0/tests/test_flag_module.py +54 -0
- intempt-4.0.0/tests/test_flag_stream.py +397 -0
- intempt-4.0.0/tests/test_flags.py +910 -0
- intempt-4.0.0/tests/test_flags_client.py +293 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_messages.py +12 -0
- intempt-4.0.0/tests/test_mutation_hangs.py +59 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_transport.py +64 -6
- intempt-3.0.0/docs/CONVENTIONS.md +0 -105
- intempt-3.0.0/src/intempt/__init__.py +0 -42
- intempt-3.0.0/src/intempt/_flags.py +0 -113
- intempt-3.0.0/src/intempt/_transport.py +0 -247
- intempt-3.0.0/tests/test_flags.py +0 -569
- {intempt-3.0.0 → intempt-4.0.0}/.github/workflows/autopr.yaml +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/.github/workflows/blu-bot-pipeline-caller.yml +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/.github/workflows/e2e.yml +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/.github/workflows/ff-merge.yml +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/.github/workflows/release.yml +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/.gitignore +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/LICENSE +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/NOTICE +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/docs/TESTING.md +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/examples/README.md +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/examples/bare/send.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/examples/basic/app.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/pyproject.toml +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/scripts/check-no-local-bucketing.mjs +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/scripts/e2e.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/scripts/no-local-bucketing-allow.json +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/src/intempt/_errors.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/src/intempt/_util.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/__init__.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_bare_sample.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_bucketing_guard.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_config.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_credential_guard.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_e2e_script.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_example_app.py +0 -0
- {intempt-3.0.0 → intempt-4.0.0}/tests/test_thresholds.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"lane":"BUG","ref":"INT-7291","test":"tests/test_transport.py"}
|
|
@@ -8,6 +8,12 @@ on:
|
|
|
8
8
|
permissions:
|
|
9
9
|
contents: read
|
|
10
10
|
|
|
11
|
+
# A new push to a PR supersedes its running checks; superseded mutation runs held self-hosted
|
|
12
|
+
# runners for hours (run 46834486114 on 9adbd45). Pushes to main are never cancelled.
|
|
13
|
+
concurrency:
|
|
14
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
15
|
+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
16
|
+
|
|
11
17
|
jobs:
|
|
12
18
|
# R36: the platform decides which variant a person gets. An SDK that derives its own
|
|
13
19
|
# bucket can disagree with the server, and the same person is then served differently
|
|
@@ -61,6 +67,8 @@ jobs:
|
|
|
61
67
|
# 3.12 specifically: mutmut needs libcst, and libcst has no prebuilt wheel
|
|
62
68
|
# for 3.14 yet, so it tries to compile Rust and fails.
|
|
63
69
|
runs-on: intempt-ubuntu-github-runner
|
|
70
|
+
# The last green run took 35 min. Without a limit a hung step runs to GitHub's 6 h default.
|
|
71
|
+
timeout-minutes: 60
|
|
64
72
|
steps:
|
|
65
73
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
66
74
|
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
|
|
@@ -37,7 +37,12 @@ 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
|
-
| `
|
|
40
|
+
| `choose(context, names=, groups=)` | `POST …/optimization/choose-api` |
|
|
41
|
+
| `variation` / `variation_detail` / typed `*_variation` | `POST …/flags/evaluate` (`/flags/all` with `disable_exposure`) |
|
|
42
|
+
| `all_flags(context)` | `POST …/flags/all`; first read of a served key `POST …/flags/expose` |
|
|
43
|
+
| flag cache invalidation | `GET …/flags/stream` (one SSE connection per process) |
|
|
44
|
+
| `postfork()` | — |
|
|
45
|
+
| `opt_in()` / `opt_out()` / `is_opted_in()` / `has_opted_out()` | — |
|
|
41
46
|
| `flush()` / `close()` | — |
|
|
42
47
|
| `set_config(patch)` / `config` / `buffered` | — |
|
|
43
48
|
|
|
@@ -46,8 +51,8 @@ path is `…/track` rather than `…/sources/{id}/track`.
|
|
|
46
51
|
|
|
47
52
|
### Deliberately absent
|
|
48
53
|
|
|
49
|
-
- **
|
|
50
|
-
|
|
54
|
+
- **Web experiences that modify a page.** A server has no page; these belong to the
|
|
55
|
+
browser SDK. API-channel experiments and personalizations are `choose()`.
|
|
51
56
|
- **`profile_id` and `master_id`.** `profile_id` is the anonymous id the browser SDK
|
|
52
57
|
mints on the device; a server that invents one creates an orphan profile that never
|
|
53
58
|
stitches to a real visitor. `master_id` is assigned internally after identity
|
|
@@ -100,9 +105,12 @@ different source. Never coerce an id numerically, in any language, at any layer.
|
|
|
100
105
|
|
|
101
106
|
### Delivery is at-least-once
|
|
102
107
|
|
|
103
|
-
Ingestion has no idempotency key.
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
Ingestion has no idempotency key. Inside one request, payload items that share an
|
|
109
|
+
`event_id` are stored as one row: measured 2026-11-16 (INT-5415, INT-5410), an order
|
|
110
|
+
with two lines and one shared id stored one row, and with an id per line it stored two.
|
|
111
|
+
So every payload item carries its own `event_id`. Whether a resend of a request that
|
|
112
|
+
already landed is collapsed is not measured, so the SDK assumes it is not. That is why
|
|
113
|
+
nothing that may have landed is resent.
|
|
106
114
|
|
|
107
115
|
### close() is bounded
|
|
108
116
|
|
|
@@ -117,9 +125,10 @@ reach the wait check).
|
|
|
117
125
|
|
|
118
126
|
### opt-out gates buffered events too
|
|
119
127
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
`opt_out()` discards the queue (SDK-API-CONTRACT optOut), so an `opt_in()` before the
|
|
129
|
+
next flush does not send events captured before the objection. It keeps a batch already
|
|
130
|
+
being sent, because the flush deletes that batch by position when the send returns; the
|
|
131
|
+
gate in the send path drops it instead.
|
|
123
132
|
|
|
124
133
|
## Quality bar
|
|
125
134
|
|
|
@@ -1,6 +1,110 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 4.0.0 — 2026-12-02 — breaking
|
|
4
|
+
|
|
5
|
+
Aligns flags and experiments with intempt-node (SDK-ALIGN). Flags move off
|
|
6
|
+
`/optimization/choose-api` onto the flag routes, because audience-service stops serving
|
|
7
|
+
flags through choose-api (D20): on the released versions `variation` and `all_flags`
|
|
8
|
+
would then return only the default.
|
|
9
|
+
|
|
10
|
+
### Changed — breaking
|
|
11
|
+
|
|
12
|
+
- **`opt_out()` discards the buffered events at once** (SDK-API-CONTRACT optOut). Before,
|
|
13
|
+
they were dropped only at send, so an `opt_in()` before the next flush still sent events
|
|
14
|
+
captured before the `opt_out()`. A batch already being sent is dropped by the send-time
|
|
15
|
+
gate.
|
|
16
|
+
- **`variation` and friends read flags only.** `variation`, `variation_detail`,
|
|
17
|
+
`bool_variation`, `string_variation`, `number_variation` and `json_variation` read
|
|
18
|
+
`POST /flags/evaluate` (one key; the server records the exposure), or `/flags/all` for
|
|
19
|
+
that key with `disable_exposure=True`. They no longer resolve an experiment or a
|
|
20
|
+
personalization by key: read those with the new `choose()`. There is no fallback to
|
|
21
|
+
choose-api.
|
|
22
|
+
- **`all_flags(context)` reads `POST /flags/all` and returns a `FlagMap`**, not a `dict`.
|
|
23
|
+
The call records nothing; the first read of each served key from the map
|
|
24
|
+
(`m[key]`, `m.get(key)`, or anything that reads every value) sends `/flags/expose` once,
|
|
25
|
+
in the background. Listing keys, `len` and `in` expose nothing. `json.dumps(m)` needs
|
|
26
|
+
`dict(m)`, which exposes every served key. A key the server returns with nothing served
|
|
27
|
+
maps to `None` (it used to be left out). The `log_exposure` argument is removed.
|
|
28
|
+
- **No flag read raises for a caller mistake** (S11). A bad key returns the default with
|
|
29
|
+
`reason="error"`, `error_code="FLAG_NOT_FOUND"`; a context with no usable identity (or
|
|
30
|
+
not a `FlagContext`) returns it with `TARGETING_KEY_MISSING`; each logs one warning per
|
|
31
|
+
key. They used to raise `IntemptConfigError`. A closed client still raises.
|
|
32
|
+
- **A wrong-typed value is `TYPE_MISMATCH`** (F30), checked against the server's declared
|
|
33
|
+
`valueType` when sent. `json_variation` accepts any JSON value, arrays and scalars
|
|
34
|
+
included. A 404 is `FLAG_NOT_FOUND`; a 500 is `GENERAL`.
|
|
35
|
+
- **`FlagDetail` carries the server's answer** (F6): `reason` is passed through
|
|
36
|
+
(`targeted`, `not_targeted`, `not_in_rollout`, `off`, `killed`, `not_client_side`), plus
|
|
37
|
+
`error_code`, `variation_id`, `value_type`, `rule` and `variant`. `FlagReason` is now
|
|
38
|
+
`str`; `holdout` is gone.
|
|
39
|
+
- **408 is `timeout` and 429 is `server`** in `FlagError.kind` (they were `bad_request`).
|
|
40
|
+
- **Flag and choose reads time out at `flag_timeout`, 2 s by default** (S11, D19), and
|
|
41
|
+
wait for a request slot no longer than that. Tracking keeps `timeout`.
|
|
42
|
+
|
|
43
|
+
### Deprecated
|
|
44
|
+
|
|
45
|
+
- **`wait_for_initialization()`** does nothing (there is nothing to load) and now emits a
|
|
46
|
+
`DeprecationWarning`; removed in the next major.
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- **`choose(context, names=, groups=, disable_exposure=)`** (D13): experiments and
|
|
51
|
+
personalizations over `/optimization/choose-api`, returning `list[Choice]` (`name`,
|
|
52
|
+
`body`, `group`, `experience_id`, `variant_id`, `reason`). A runtime failure returns
|
|
53
|
+
`[]` after one log line; a context with no identity or a name the service would refuse
|
|
54
|
+
raises `IntemptConfigError`. `ChooseContext` or `FlagContext` is accepted.
|
|
55
|
+
- **Flag cache and stream** (F15): one `GET /flags/stream` connection per process
|
|
56
|
+
(reconnects 1 s doubling to 60 s); while it is connected an answer younger than 60 s is
|
|
57
|
+
served from memory and a `flags_changed` event drops the named keys at once. A read that
|
|
58
|
+
fails for a reason that may recover serves the last-known value for up to 24 h with
|
|
59
|
+
reason `cached`. At most 10,000 entries. A `disable_exposure` answer never serves a
|
|
60
|
+
read that owes an exposure; a read served from memory sends nothing, as in Node. A flag read
|
|
61
|
+
of the wrong type logs one `TYPE_MISMATCH` warning per key.
|
|
62
|
+
- **`postfork()`**: starts the flag stream, cache trust and connection pool over in a
|
|
63
|
+
forked worker (gunicorn `post_fork`, uWSGI `@postfork`), as LaunchDarkly Python 9.11+.
|
|
64
|
+
On POSIX it also runs by itself after `os.fork()`.
|
|
65
|
+
- **`flag_timeout`** option, settable with `set_config`.
|
|
66
|
+
- `FlagContext.session_id` is sent on `/flags/evaluate` and `/flags/expose`.
|
|
67
|
+
- **`IntemptFlags(**config)`**, the flags-only client, after intempt-node's
|
|
68
|
+
`IntemptFlagsClient`: `variation`, `variation_detail`, the typed variations, `all_flags`,
|
|
69
|
+
`postfork`, `close()` and `with`. It builds the transport and the flag cache and stream
|
|
70
|
+
only: no event buffer, no exit hook, and `from intempt import IntemptFlags` imports none
|
|
71
|
+
of the tracking modules (the package now loads `Intempt` and the other tracking names on
|
|
72
|
+
first use). Takes `Intempt`'s options and credential; `batch`, `max_request_events`,
|
|
73
|
+
`max_concurrent_requests` and `on_delivery_failure` raise `IntemptConfigError`, as Node's
|
|
74
|
+
`IntemptFlagsConfig` leaves out the same four.
|
|
75
|
+
|
|
76
|
+
### Fixed
|
|
77
|
+
|
|
78
|
+
- **A batching client survives a fork.** A client made before `os.fork()` (gunicorn or
|
|
79
|
+
uWSGI preload, `multiprocessing`) gave each child a buffer whose flush timer was dead, so
|
|
80
|
+
the child auto-flushed nothing, could block on a lock a parent thread held, and its
|
|
81
|
+
`flush()` re-sent the events the parent had queued. `postfork()`, which also runs by
|
|
82
|
+
itself after `os.fork()` on POSIX, now starts the child's buffer empty with new locks and
|
|
83
|
+
a new timer; events queued before the fork are sent by the parent only.
|
|
84
|
+
|
|
85
|
+
## 3.1.0 — unreleased
|
|
86
|
+
|
|
87
|
+
### Added
|
|
88
|
+
|
|
89
|
+
- **`has_opted_out()`** (INT-5416), the inverse of `is_opted_in()`: true after
|
|
90
|
+
`opt_out()` and after `close()`. The public docs already name it.
|
|
91
|
+
|
|
92
|
+
### Changed — behaviour
|
|
93
|
+
|
|
94
|
+
- **A `datetime` or `date` inside `properties`, `user_attributes` or
|
|
95
|
+
`account_attributes` is sent as an ISO-8601 UTC string with milliseconds**
|
|
96
|
+
(INT-5418), `YYYY-MM-DDTHH:MM:SS.sssZ`, as the Swift, JS, Node and React Native SDKs
|
|
97
|
+
send it. Before, a `datetime` went out as epoch milliseconds and a `date` raised
|
|
98
|
+
`TypeError`. A naive `datetime` is read as UTC (it was read as local time); a `date`
|
|
99
|
+
is midnight UTC. The event `timestamp` option is unchanged and stays epoch
|
|
100
|
+
milliseconds.
|
|
101
|
+
|
|
102
|
+
### Fixed
|
|
103
|
+
|
|
104
|
+
- **`ecommerce.ordered()` gives each product line its own `eventId`** (INT-5415).
|
|
105
|
+
The lines shared one id, and the server kept only one line of a multi-product order.
|
|
106
|
+
|
|
107
|
+
## 3.0.0 — 2026-11-13
|
|
4
108
|
|
|
5
109
|
### Changed — breaking
|
|
6
110
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: intempt
|
|
3
|
-
Version:
|
|
3
|
+
Version: 4.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
|
|
@@ -82,7 +82,7 @@ other short-lived processes.
|
|
|
82
82
|
| `ecommerce.added_to_cart(product_id=…, quantity=…, **ids)` | `bool` | `POST …/track` |
|
|
83
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()` | — | — |
|
|
85
|
+
| `opt_in()` / `opt_out()` / `is_opted_in()` / `has_opted_out()` | — | — |
|
|
86
86
|
| `flush()` / `close()` | `FlushResult(sent, failed)` | — |
|
|
87
87
|
| `set_config(**patch)` / `config` / `buffered` | — | — |
|
|
88
88
|
|
|
@@ -94,6 +94,25 @@ retry_after)`. A bad argument or a closed client still raises `IntemptConfigErro
|
|
|
94
94
|
`recommend()` still raises `IntemptApiError`. The return values in the table above that say
|
|
95
95
|
`None` are `bool` for these write methods.
|
|
96
96
|
|
|
97
|
+
### Flags only
|
|
98
|
+
|
|
99
|
+
A backend that only checks flags can use `IntemptFlags`: `Intempt`'s flag methods (`variation`,
|
|
100
|
+
`variation_detail`, the typed variations, `all_flags`, `postfork`) on their own transport, with
|
|
101
|
+
no event buffer, no exit hook, and no import of the tracking code.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from intempt import FlagContext, IntemptFlags
|
|
105
|
+
|
|
106
|
+
with IntemptFlags(
|
|
107
|
+
org="my-org", project="my-project", api_key=os.environ["INTEMPT_API_KEY"]
|
|
108
|
+
) as flags:
|
|
109
|
+
if flags.bool_variation("new_checkout", FlagContext(user_id="user@example.com"), False):
|
|
110
|
+
...
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
It takes the same options as `Intempt` except the tracking ones (`batch`,
|
|
114
|
+
`max_request_events`, `max_concurrent_requests`, `on_delivery_failure`), which it refuses. `close()` returns `None`.
|
|
115
|
+
|
|
97
116
|
## Identifiers
|
|
98
117
|
|
|
99
118
|
Every call takes at least one of two, and both are values you already own:
|
|
@@ -158,9 +177,9 @@ At `max_queue` the oldest queued event that no send is carrying is dropped and r
|
|
|
158
177
|
|
|
159
178
|
The buffer is in memory. A hard crash loses it.
|
|
160
179
|
|
|
161
|
-
**Ingestion has no idempotency key
|
|
162
|
-
|
|
163
|
-
|
|
180
|
+
**Ingestion has no idempotency key.** Payload items of one request that share an
|
|
181
|
+
`eventId` are stored as one row (measured, INT-5415), so each item gets its own id.
|
|
182
|
+
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
183
|
never resent: the SDK trades a possible loss, which it reports, for no duplicates.
|
|
165
184
|
|
|
166
185
|
## Timestamps
|
|
@@ -168,6 +187,10 @@ never resent: the SDK trades a possible loss, which it reports, for no duplicate
|
|
|
168
187
|
`timestamp` accepts a `datetime` or epoch milliseconds. A naive `datetime` is treated
|
|
169
188
|
as UTC, not local time.
|
|
170
189
|
|
|
190
|
+
A `datetime` or `date` inside `properties` or the attribute maps is sent as an ISO-8601
|
|
191
|
+
UTC string with milliseconds (`2026-01-01T09:30:05.123Z`), the same as the other SDKs.
|
|
192
|
+
Naive is UTC there too; a `date` is midnight UTC.
|
|
193
|
+
|
|
171
194
|
It **is** a backfill mechanism, between 2010 and 2040. The event store keeps your value
|
|
172
195
|
and records arrival separately, so the two never overwrite each other.
|
|
173
196
|
|
|
@@ -188,16 +211,17 @@ intempt.opt_out() # suppresses track, batch and commerce; consent is still sent
|
|
|
188
211
|
intempt.opt_in()
|
|
189
212
|
```
|
|
190
213
|
|
|
191
|
-
|
|
192
|
-
|
|
214
|
+
`opt_out()` discards the events already buffered, so an `opt_in()` before the next flush
|
|
215
|
+
does not send them. The gate is also applied when events are sent, so a batch already
|
|
216
|
+
being sent at `opt_out()` is dropped too.
|
|
193
217
|
|
|
194
218
|
## Not in this SDK
|
|
195
219
|
|
|
196
220
|
Console and configuration operations — journeys, dashboards, segments, brand — belong
|
|
197
221
|
to the CLI and the MCP server, not to a data-plane SDK.
|
|
198
222
|
|
|
199
|
-
|
|
200
|
-
|
|
223
|
+
Web experiences that modify a page are absent: a server has no page. API-channel
|
|
224
|
+
experiments and personalizations are read with `choose()`, and flags with `variation()`.
|
|
201
225
|
|
|
202
226
|
## License
|
|
203
227
|
|
|
@@ -55,7 +55,7 @@ other short-lived processes.
|
|
|
55
55
|
| `ecommerce.added_to_cart(product_id=…, quantity=…, **ids)` | `bool` | `POST …/track` |
|
|
56
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()` | — | — |
|
|
58
|
+
| `opt_in()` / `opt_out()` / `is_opted_in()` / `has_opted_out()` | — | — |
|
|
59
59
|
| `flush()` / `close()` | `FlushResult(sent, failed)` | — |
|
|
60
60
|
| `set_config(**patch)` / `config` / `buffered` | — | — |
|
|
61
61
|
|
|
@@ -67,6 +67,25 @@ retry_after)`. A bad argument or a closed client still raises `IntemptConfigErro
|
|
|
67
67
|
`recommend()` still raises `IntemptApiError`. The return values in the table above that say
|
|
68
68
|
`None` are `bool` for these write methods.
|
|
69
69
|
|
|
70
|
+
### Flags only
|
|
71
|
+
|
|
72
|
+
A backend that only checks flags can use `IntemptFlags`: `Intempt`'s flag methods (`variation`,
|
|
73
|
+
`variation_detail`, the typed variations, `all_flags`, `postfork`) on their own transport, with
|
|
74
|
+
no event buffer, no exit hook, and no import of the tracking code.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from intempt import FlagContext, IntemptFlags
|
|
78
|
+
|
|
79
|
+
with IntemptFlags(
|
|
80
|
+
org="my-org", project="my-project", api_key=os.environ["INTEMPT_API_KEY"]
|
|
81
|
+
) as flags:
|
|
82
|
+
if flags.bool_variation("new_checkout", FlagContext(user_id="user@example.com"), False):
|
|
83
|
+
...
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
It takes the same options as `Intempt` except the tracking ones (`batch`,
|
|
87
|
+
`max_request_events`, `max_concurrent_requests`, `on_delivery_failure`), which it refuses. `close()` returns `None`.
|
|
88
|
+
|
|
70
89
|
## Identifiers
|
|
71
90
|
|
|
72
91
|
Every call takes at least one of two, and both are values you already own:
|
|
@@ -131,9 +150,9 @@ At `max_queue` the oldest queued event that no send is carrying is dropped and r
|
|
|
131
150
|
|
|
132
151
|
The buffer is in memory. A hard crash loses it.
|
|
133
152
|
|
|
134
|
-
**Ingestion has no idempotency key
|
|
135
|
-
|
|
136
|
-
|
|
153
|
+
**Ingestion has no idempotency key.** Payload items of one request that share an
|
|
154
|
+
`eventId` are stored as one row (measured, INT-5415), so each item gets its own id.
|
|
155
|
+
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
156
|
never resent: the SDK trades a possible loss, which it reports, for no duplicates.
|
|
138
157
|
|
|
139
158
|
## Timestamps
|
|
@@ -141,6 +160,10 @@ never resent: the SDK trades a possible loss, which it reports, for no duplicate
|
|
|
141
160
|
`timestamp` accepts a `datetime` or epoch milliseconds. A naive `datetime` is treated
|
|
142
161
|
as UTC, not local time.
|
|
143
162
|
|
|
163
|
+
A `datetime` or `date` inside `properties` or the attribute maps is sent as an ISO-8601
|
|
164
|
+
UTC string with milliseconds (`2026-01-01T09:30:05.123Z`), the same as the other SDKs.
|
|
165
|
+
Naive is UTC there too; a `date` is midnight UTC.
|
|
166
|
+
|
|
144
167
|
It **is** a backfill mechanism, between 2010 and 2040. The event store keeps your value
|
|
145
168
|
and records arrival separately, so the two never overwrite each other.
|
|
146
169
|
|
|
@@ -161,16 +184,17 @@ intempt.opt_out() # suppresses track, batch and commerce; consent is still sent
|
|
|
161
184
|
intempt.opt_in()
|
|
162
185
|
```
|
|
163
186
|
|
|
164
|
-
|
|
165
|
-
|
|
187
|
+
`opt_out()` discards the events already buffered, so an `opt_in()` before the next flush
|
|
188
|
+
does not send them. The gate is also applied when events are sent, so a batch already
|
|
189
|
+
being sent at `opt_out()` is dropped too.
|
|
166
190
|
|
|
167
191
|
## Not in this SDK
|
|
168
192
|
|
|
169
193
|
Console and configuration operations — journeys, dashboards, segments, brand — belong
|
|
170
194
|
to the CLI and the MCP server, not to a data-plane SDK.
|
|
171
195
|
|
|
172
|
-
|
|
173
|
-
|
|
196
|
+
Web experiences that modify a page are absent: a server has no page. API-channel
|
|
197
|
+
experiments and personalizations are read with `choose()`, and flags with `variation()`.
|
|
174
198
|
|
|
175
199
|
## License
|
|
176
200
|
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Conventions
|
|
2
|
+
|
|
3
|
+
**The cross-SDK surface is not decided here.** Every Intempt SDK conforms to
|
|
4
|
+
`intempt-swift/docs/SDK-API-CONTRACT.md`, which is the single authority on method names, argument
|
|
5
|
+
order, defaults and what is deliberately withheld. This file covers what is specific to Python and
|
|
6
|
+
to this repo. Where the two disagree, the contract wins and this file is the bug.
|
|
7
|
+
|
|
8
|
+
## The rules that come from the contract
|
|
9
|
+
|
|
10
|
+
- **A flag is read by key; experiments and personalizations by `choose()`** (D13, D20). `variation`
|
|
11
|
+
and friends read only flags, from the flag routes (`/flags/evaluate`, `/flags/all`,
|
|
12
|
+
`/flags/expose`, `/flags/stream`); `choose()` is the one call for `/optimization/choose-api`. A
|
|
13
|
+
flag read never falls back to choose-api: once audience-service stops serving flags there, such a
|
|
14
|
+
fallback would only ever return defaults while looking like it worked.
|
|
15
|
+
- **`defaultValue` is REQUIRED, everywhere, and is never optional.** It is what a caller receives on
|
|
16
|
+
a network failure, a timeout, an unknown key or a malformed response. A flag SDK that throws when
|
|
17
|
+
the service is unreachable takes the application down with it, which is the opposite of what a
|
|
18
|
+
kill switch is for.
|
|
19
|
+
- **A wrong-typed value falls back; it is never coerced** (F30). The default's type is the expected
|
|
20
|
+
type, and the server's declared `valueType` decides when sent: a mismatch returns the default with
|
|
21
|
+
`reason="error"`, `error_code="TYPE_MISMATCH"`. A `None` default expects nothing in particular.
|
|
22
|
+
- **`variation_detail` passes the server's answer through** (F6): `reason` (`targeted`,
|
|
23
|
+
`not_targeted`, `not_in_rollout`, `off`, `killed`, `not_client_side`, or one added later),
|
|
24
|
+
`variation_id`, `value_type`, `rule`, `variant`. `error` means the default came back for a known
|
|
25
|
+
cause, with an OpenFeature `error_code`; `cached` means a failed read served the last-known value.
|
|
26
|
+
- **Evaluation is REMOTE only.** No local rule engine, no flag store to poll, and no hashing
|
|
27
|
+
utility: the server buckets, so no second implementation can disagree with it. `check-no-local-bucketing.mjs`
|
|
28
|
+
enforces this in CI and a new bucketing helper will fail the build.
|
|
29
|
+
- **No flag read raises; `choose()` raises only for a malformed call** (S11). A flag read with a bad
|
|
30
|
+
key, an unusable context or a wrong type returns the default and logs one warning per key, so a
|
|
31
|
+
typo stays visible without taking a request down. `choose()` raises `IntemptConfigError` for a
|
|
32
|
+
context with no identity or a name the service would refuse, as intempt-node rejects. A closed
|
|
33
|
+
client raises on both.
|
|
34
|
+
|
|
35
|
+
## What the flag path checks before it sends
|
|
36
|
+
|
|
37
|
+
Each check below returns the default instead of sending a request the service would refuse, because
|
|
38
|
+
a refused request is the caller's default, returned forever, indistinguishable from a flag
|
|
39
|
+
deliberately serving it. The warning, once per key, is what makes it findable.
|
|
40
|
+
|
|
41
|
+
- **The identity must be one the service can answer.** The flag routes take choose-api's
|
|
42
|
+
`Identification` and answer 400 unless it names a visitor: a non-blank `user_id`, or a non-blank
|
|
43
|
+
`profile_id` with a configured `source_id`. Otherwise `TARGETING_KEY_MISSING`.
|
|
44
|
+
- **The key must match `^[a-zA-Z0-9_-]+$`** (`fullmatch`: `$` alone also matches before a trailing
|
|
45
|
+
newline). Otherwise `FLAG_NOT_FOUND`, as the server answers an unknown key.
|
|
46
|
+
- **`device` is sent on every request and is load-bearing.** A null device becomes the SQL
|
|
47
|
+
predicate `"0"` server-side, which is false for every row, so omitting it returns nothing rather
|
|
48
|
+
than an error. `tests/test_flags.py` asserts it goes over the wire.
|
|
49
|
+
|
|
50
|
+
`session_id` is never an identifier. On a flag read it is recorded on the exposure; on `choose()`
|
|
51
|
+
it also gates a `once` / `once_per_visit` experience, so without one the second read of such an
|
|
52
|
+
experience returns nothing.
|
|
53
|
+
|
|
54
|
+
## Cache, stream and fork (F15)
|
|
55
|
+
|
|
56
|
+
One `/flags/stream` connection and one cache per process. While the stream is connected, an answer
|
|
57
|
+
younger than 60 s is served without asking, because a `flags_changed` event drops the named keys at
|
|
58
|
+
once; without a stream every read asks. A read that fails for a reason that may recover (timeout,
|
|
59
|
+
network, 408, 429, 5xx, unparseable) serves the last-known value for up to 24 h with reason
|
|
60
|
+
`cached`; a 404 forgets it. At most 10,000 entries, oldest dropped. Flag and choose reads use
|
|
61
|
+
`flag_timeout` (2 s), tracking keeps `timeout` (10 s), and a flag read waits for a request slot no
|
|
62
|
+
longer than its own timeout.
|
|
63
|
+
|
|
64
|
+
A pre-fork server copies the parent's stream state into each worker but not its reader thread, so
|
|
65
|
+
`Intempt.postfork()` starts the flag state and the connection pool over; it also runs by itself
|
|
66
|
+
after `os.fork()` on POSIX. It also starts the event buffer over, empty, with a new timer: events
|
|
67
|
+
queued before the fork are the parent's to send, so a child that kept them would send them twice.
|
|
68
|
+
|
|
69
|
+
## Credentials
|
|
70
|
+
|
|
71
|
+
**What this SDK does, which is the only part settled here.** One `api_key` in `<prefix>.<secret>`
|
|
72
|
+
form serves ingest and evaluation alike, sent as HTTP **Basic** — not Bearer — on every request
|
|
73
|
+
including the flag routes and `POST /optimization/choose-api`. Never log the credential and never put it in a URL.
|
|
74
|
+
|
|
75
|
+
**What is NOT settled: whether evaluation should require a credential distinct from the ingest
|
|
76
|
+
one.** An earlier draft of this file asserted that the endpoint takes a *server* credential and
|
|
77
|
+
refuses a public key. That assertion is withdrawn: it was never verified against the service, and
|
|
78
|
+
it contradicted this SDK's own transport, which accepts a key its error text calls public and then
|
|
79
|
+
sends it to that endpoint. If it had been true, the flag surface could not work at all.
|
|
80
|
+
|
|
81
|
+
The question behind it is real — the evaluation response describes how every experience in the
|
|
82
|
+
project targets, which is not obviously public — but it is a **product decision about the
|
|
83
|
+
credential model, and it is unruled**. It is not settleable inside an SDK repo, and this file must
|
|
84
|
+
not settle it by describing a rule nobody made. **Owner: Sid.** Until it is ruled, treat the
|
|
85
|
+
paragraph above as the contract and do not re-add a claim about what the endpoint refuses without
|
|
86
|
+
a reading of the service's security configuration to cite.
|
|
87
|
+
|
|
88
|
+
## Python specifics
|
|
89
|
+
|
|
90
|
+
- **Naming follows the language, not the contract's spelling.** The contract's `allFlags` is
|
|
91
|
+
`all_flags` here, `variationDetail` is `variation_detail` (public since INT-7454),
|
|
92
|
+
`onFlagError` is `on_flag_error`, `onDeliveryFailure` is `on_delivery_failure` and
|
|
93
|
+
`disableExposure` is `disable_exposure`; the shape is identical, the case is not. A contract
|
|
94
|
+
`shutdown()` is `close()` here, the name this SDK already had.
|
|
95
|
+
- **The mutation threshold is 70, not 85.** That is a measured decision, not an oversight: mutmut's
|
|
96
|
+
operator set produces a materially different denominator from Stryker's and Infection's, and 70 here
|
|
97
|
+
was the level at which surviving mutants were genuinely equivalent rather than untested. Raising it
|
|
98
|
+
to match the others without re-measuring would be cargo-culting a number across tools.
|
|
@@ -17,15 +17,29 @@ Licensed under the Apache License, Version 2.0.
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import argparse
|
|
20
|
+
import contextlib
|
|
20
21
|
import json
|
|
22
|
+
import os
|
|
21
23
|
import re
|
|
24
|
+
import signal
|
|
22
25
|
import subprocess
|
|
23
26
|
import sys
|
|
27
|
+
import tempfile
|
|
24
28
|
|
|
25
29
|
|
|
26
30
|
def run(command: list[str]) -> tuple[int, str]:
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
# Not a pipe: a forked test child a mutant left hanging outlives mutmut and keeps the pipe open,
|
|
32
|
+
# so reading it to EOF waited until the job was cancelled (run 46841654510, 2 h 52 m). Only
|
|
33
|
+
# mutmut itself is waited on; its process group, strays included, is killed afterwards.
|
|
34
|
+
with tempfile.TemporaryFile(mode="w+") as out:
|
|
35
|
+
proc = subprocess.Popen(
|
|
36
|
+
command, stdout=out, stderr=subprocess.STDOUT, text=True, start_new_session=True
|
|
37
|
+
)
|
|
38
|
+
code = proc.wait()
|
|
39
|
+
with contextlib.suppress(ProcessLookupError):
|
|
40
|
+
os.killpg(proc.pid, signal.SIGKILL)
|
|
41
|
+
out.seek(0)
|
|
42
|
+
return code, out.read()
|
|
29
43
|
|
|
30
44
|
|
|
31
45
|
def parse_results(text: str) -> dict[str, int]:
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Intempt Python SDK — server-side. Data in, decisions out.
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Intempt Technologies
|
|
4
|
+
Licensed under the Apache License, Version 2.0.
|
|
5
|
+
|
|
6
|
+
Contains code derived from mixpanel-python (Apache License 2.0); see NOTICE.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from importlib import import_module
|
|
12
|
+
from typing import TYPE_CHECKING, Any
|
|
13
|
+
|
|
14
|
+
from ._config import BatchOptions, ResolvedConfig
|
|
15
|
+
from ._errors import IntemptApiError, IntemptConfigError, IntemptError
|
|
16
|
+
from ._flags import FlagContext, FlagDetail, FlagError, FlagErrorCode, FlagMap, FlagReason
|
|
17
|
+
from ._flags_client import IntemptFlags
|
|
18
|
+
from ._transport import ApiKeyCredentials, Transport
|
|
19
|
+
|
|
20
|
+
if TYPE_CHECKING:
|
|
21
|
+
from ._buffer import Buffer
|
|
22
|
+
from ._choose import Choice, ChooseContext
|
|
23
|
+
from ._client import COMMERCE_EVENTS, IDENTIFY_EVENT, Consent, Ecommerce, Intempt
|
|
24
|
+
from ._delivery import DeliveryFailure, FlushResult
|
|
25
|
+
|
|
26
|
+
# Loaded on first use (PEP 562), so `from intempt import IntemptFlags` never imports the event
|
|
27
|
+
# buffer, delivery or the full client (F33). tests/test_flags_client.py checks sys.modules.
|
|
28
|
+
_LAZY = {
|
|
29
|
+
"Buffer": "._buffer",
|
|
30
|
+
"Choice": "._choose",
|
|
31
|
+
"ChooseContext": "._choose",
|
|
32
|
+
"COMMERCE_EVENTS": "._client",
|
|
33
|
+
"IDENTIFY_EVENT": "._client",
|
|
34
|
+
"Consent": "._client",
|
|
35
|
+
"Ecommerce": "._client",
|
|
36
|
+
"Intempt": "._client",
|
|
37
|
+
"DeliveryFailure": "._delivery",
|
|
38
|
+
"FlushResult": "._delivery",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def __getattr__(name: str) -> Any:
|
|
43
|
+
module = _LAZY.get(name)
|
|
44
|
+
if module is None:
|
|
45
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
46
|
+
value = getattr(import_module(module, __name__), name)
|
|
47
|
+
globals()[name] = value
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def __dir__() -> list[str]:
|
|
52
|
+
return sorted(set(globals()) | set(_LAZY))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
__version__ = "4.0.0"
|
|
56
|
+
|
|
57
|
+
__all__ = [
|
|
58
|
+
"Intempt",
|
|
59
|
+
"IntemptFlags",
|
|
60
|
+
"IntemptError",
|
|
61
|
+
"IntemptApiError",
|
|
62
|
+
"IntemptConfigError",
|
|
63
|
+
"BatchOptions",
|
|
64
|
+
"DeliveryFailure",
|
|
65
|
+
"FlushResult",
|
|
66
|
+
"ResolvedConfig",
|
|
67
|
+
"ApiKeyCredentials",
|
|
68
|
+
"Transport",
|
|
69
|
+
"Buffer",
|
|
70
|
+
"Consent",
|
|
71
|
+
"Ecommerce",
|
|
72
|
+
"COMMERCE_EVENTS",
|
|
73
|
+
"IDENTIFY_EVENT",
|
|
74
|
+
"FlagContext",
|
|
75
|
+
"FlagDetail",
|
|
76
|
+
"FlagError",
|
|
77
|
+
"FlagReason",
|
|
78
|
+
"FlagErrorCode",
|
|
79
|
+
"FlagMap",
|
|
80
|
+
"Choice",
|
|
81
|
+
"ChooseContext",
|
|
82
|
+
"__version__",
|
|
83
|
+
]
|