featurevisor 0.2.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 (35) hide show
  1. featurevisor-0.2.0/LICENSE +21 -0
  2. featurevisor-0.2.0/PKG-INFO +374 -0
  3. featurevisor-0.2.0/README.md +357 -0
  4. featurevisor-0.2.0/pyproject.toml +31 -0
  5. featurevisor-0.2.0/setup.cfg +4 -0
  6. featurevisor-0.2.0/src/featurevisor/__init__.py +52 -0
  7. featurevisor-0.2.0/src/featurevisor/__main__.py +4 -0
  8. featurevisor-0.2.0/src/featurevisor/bucketer.py +43 -0
  9. featurevisor-0.2.0/src/featurevisor/child.py +100 -0
  10. featurevisor-0.2.0/src/featurevisor/cli.py +93 -0
  11. featurevisor-0.2.0/src/featurevisor/compare_versions.py +65 -0
  12. featurevisor-0.2.0/src/featurevisor/conditions.py +97 -0
  13. featurevisor-0.2.0/src/featurevisor/datafile_reader.py +154 -0
  14. featurevisor-0.2.0/src/featurevisor/emitter.py +43 -0
  15. featurevisor-0.2.0/src/featurevisor/evaluate.py +454 -0
  16. featurevisor-0.2.0/src/featurevisor/events.py +40 -0
  17. featurevisor-0.2.0/src/featurevisor/helpers.py +28 -0
  18. featurevisor-0.2.0/src/featurevisor/hooks.py +31 -0
  19. featurevisor-0.2.0/src/featurevisor/instance.py +200 -0
  20. featurevisor-0.2.0/src/featurevisor/logger.py +50 -0
  21. featurevisor-0.2.0/src/featurevisor/murmurhash.py +45 -0
  22. featurevisor-0.2.0/src/featurevisor/project.py +95 -0
  23. featurevisor-0.2.0/src/featurevisor/tester.py +343 -0
  24. featurevisor-0.2.0/src/featurevisor/types.py +192 -0
  25. featurevisor-0.2.0/src/featurevisor.egg-info/PKG-INFO +374 -0
  26. featurevisor-0.2.0/src/featurevisor.egg-info/SOURCES.txt +33 -0
  27. featurevisor-0.2.0/src/featurevisor.egg-info/dependency_links.txt +1 -0
  28. featurevisor-0.2.0/src/featurevisor.egg-info/entry_points.txt +2 -0
  29. featurevisor-0.2.0/src/featurevisor.egg-info/top_level.txt +1 -0
  30. featurevisor-0.2.0/tests/test_cli.py +35 -0
  31. featurevisor-0.2.0/tests/test_conditions_parity.py +124 -0
  32. featurevisor-0.2.0/tests/test_datafile_reader_parity.py +98 -0
  33. featurevisor-0.2.0/tests/test_helpers_parity.py +47 -0
  34. featurevisor-0.2.0/tests/test_instance_parity.py +234 -0
  35. featurevisor-0.2.0/tests/test_sdk.py +171 -0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Fahad Heylaal (https://fahad19.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,374 @@
1
+ Metadata-Version: 2.4
2
+ Name: featurevisor
3
+ Version: 0.2.0
4
+ Summary: Featurevisor Python SDK
5
+ Author: Fahad Heylaal
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3 :: Only
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Dynamic: license-file
17
+
18
+ # featurevisor-python
19
+
20
+ This repository ports the latest Featurevisor [JavaScript SDK](https://featurevisor.com/docs/sdks/javascript/) to Python.
21
+
22
+ The package name is `featurevisor`, and it targets Python 3.10+.
23
+
24
+ This SDK is compatible with [Featurevisor](https://featurevisor.com/) v2.0 projects and above.
25
+
26
+ <!-- FEATUREVISOR_DOCS_BEGIN -->
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install featurevisor
32
+ ```
33
+
34
+ ## Initialization
35
+
36
+ Initialize the SDK with Featurevisor datafile content:
37
+
38
+ ```python
39
+ from urllib.request import urlopen
40
+ import json
41
+
42
+ from featurevisor import create_instance
43
+
44
+ datafile_url = "https://cdn.yoursite.com/datafile.json"
45
+
46
+ with urlopen(datafile_url) as response:
47
+ datafile_content = json.load(response)
48
+
49
+ f = create_instance({
50
+ "datafile": datafile_content,
51
+ })
52
+ ```
53
+
54
+ ## Evaluation Types
55
+
56
+ We can evaluate 3 types of values against a particular [feature](https://featurevisor.com/docs/features/):
57
+
58
+ - [**Flag**](#check-if-enabled) (`bool`): whether the feature is enabled or not
59
+ - [**Variation**](#getting-variation) (`string`): the variation of the feature (if any)
60
+ - [**Variables**](#getting-variables): variable values of the feature (if any)
61
+
62
+ ## Context
63
+
64
+ Context is a plain dictionary of attribute values used during evaluation:
65
+
66
+ ```python
67
+ context = {
68
+ "userId": "123",
69
+ "country": "nl",
70
+ }
71
+ ```
72
+
73
+ You can provide context at initialization:
74
+
75
+ ```python
76
+ f = create_instance({
77
+ "context": {
78
+ "deviceId": "123",
79
+ "country": "nl",
80
+ },
81
+ })
82
+ ```
83
+
84
+ You can merge more context later:
85
+
86
+ ```python
87
+ f.set_context({
88
+ "userId": "234",
89
+ })
90
+ ```
91
+
92
+ Or replace the existing context:
93
+
94
+ ```python
95
+ f.set_context(
96
+ {
97
+ "deviceId": "123",
98
+ "userId": "234",
99
+ "country": "nl",
100
+ "browser": "chrome",
101
+ },
102
+ True,
103
+ )
104
+ ```
105
+
106
+ You can also pass additional per-evaluation context:
107
+
108
+ ```python
109
+ is_enabled = f.is_enabled("my_feature", {"country": "nl"})
110
+ variation = f.get_variation("my_feature", {"country": "nl"})
111
+ variable_value = f.get_variable("my_feature", "my_variable", {"country": "nl"})
112
+ ```
113
+
114
+ ## Check If Enabled
115
+
116
+ ```python
117
+ if f.is_enabled("my_feature"):
118
+ pass
119
+ ```
120
+
121
+ ## Getting Variation
122
+
123
+ ```python
124
+ variation = f.get_variation("my_feature")
125
+
126
+ if variation == "treatment":
127
+ pass
128
+ ```
129
+
130
+ ## Getting Variables
131
+
132
+ ```python
133
+ bg_color = f.get_variable("my_feature", "bgColor")
134
+ ```
135
+
136
+ Typed convenience methods are also available:
137
+
138
+ ```python
139
+ f.get_variable_boolean(feature_key, variable_key, context={})
140
+ f.get_variable_string(feature_key, variable_key, context={})
141
+ f.get_variable_integer(feature_key, variable_key, context={})
142
+ f.get_variable_double(feature_key, variable_key, context={})
143
+ f.get_variable_array(feature_key, variable_key, context={})
144
+ f.get_variable_object(feature_key, variable_key, context={})
145
+ f.get_variable_json(feature_key, variable_key, context={})
146
+ ```
147
+
148
+ ## Getting All Evaluations
149
+
150
+ ```python
151
+ all_evaluations = f.get_all_evaluations()
152
+ ```
153
+
154
+ ## Sticky
155
+
156
+ You can pin feature evaluations with sticky values:
157
+
158
+ ```python
159
+ f = create_instance({
160
+ "sticky": {
161
+ "myFeatureKey": {
162
+ "enabled": True,
163
+ "variation": "treatment",
164
+ "variables": {
165
+ "myVariableKey": "myVariableValue",
166
+ },
167
+ }
168
+ }
169
+ })
170
+ ```
171
+
172
+ Or update them later:
173
+
174
+ ```python
175
+ f.set_sticky({
176
+ "myFeatureKey": {
177
+ "enabled": False,
178
+ }
179
+ })
180
+ ```
181
+
182
+ ## Setting Datafile
183
+
184
+ The SDK accepts either parsed JSON content or a JSON string:
185
+
186
+ ```python
187
+ f.set_datafile(datafile_content)
188
+ f.set_datafile(json.dumps(datafile_content))
189
+ ```
190
+
191
+ ## Logging
192
+
193
+ Supported log levels:
194
+
195
+ - `fatal`
196
+ - `error`
197
+ - `warn`
198
+ - `info`
199
+ - `debug`
200
+
201
+ ```python
202
+ from featurevisor import create_instance
203
+
204
+ f = create_instance({
205
+ "datafile": datafile_content,
206
+ "logLevel": "debug",
207
+ })
208
+ ```
209
+
210
+ You can also provide a custom logger handler via `create_logger`.
211
+
212
+ ## Events
213
+
214
+ The SDK emits:
215
+
216
+ - `datafile_set`
217
+ - `context_set`
218
+ - `sticky_set`
219
+
220
+ ```python
221
+ unsubscribe = f.on("datafile_set", lambda details: print(details))
222
+ unsubscribe()
223
+ ```
224
+
225
+ ## Hooks
226
+
227
+ Hooks support:
228
+
229
+ - `before`
230
+ - `bucketKey`
231
+ - `bucketValue`
232
+ - `after`
233
+
234
+ They can be passed during initialization or added later with `add_hook`.
235
+
236
+ ## Child Instance
237
+
238
+ ```python
239
+ child = f.spawn({"country": "de"})
240
+ child.is_enabled("my_feature")
241
+ ```
242
+
243
+ ## Close
244
+
245
+ ```python
246
+ f.close()
247
+ ```
248
+
249
+ ## CLI Usage
250
+
251
+ The Python package also exposes a CLI:
252
+
253
+ ```bash
254
+ python -m featurevisor test
255
+ python -m featurevisor benchmark
256
+ python -m featurevisor assess-distribution
257
+ ```
258
+
259
+ These commands are intended for use from inside a Featurevisor project and rely on `npx featurevisor` being available locally.
260
+
261
+ ### Test
262
+
263
+ Run Featurevisor test specs using the Python SDK:
264
+
265
+ ```bash
266
+ python -m featurevisor test \
267
+ --projectDirectoryPath=/path/to/featurevisor-project
268
+ ```
269
+
270
+ Useful options:
271
+
272
+ ```bash
273
+ python -m featurevisor test --keyPattern=foo
274
+ python -m featurevisor test --assertionPattern=variation
275
+ python -m featurevisor test --onlyFailures
276
+ python -m featurevisor test --showDatafile
277
+ python -m featurevisor test --verbose
278
+ python -m featurevisor test --with-tags
279
+ python -m featurevisor test --with-scopes
280
+ ```
281
+
282
+ ### Benchmark
283
+
284
+ Benchmark repeated Python SDK evaluations against a built datafile:
285
+
286
+ ```bash
287
+ python -m featurevisor benchmark \
288
+ --projectDirectoryPath=/path/to/featurevisor-project \
289
+ --environment=production \
290
+ --feature=my_feature \
291
+ --context='{"userId":"123"}' \
292
+ --n=1000
293
+ ```
294
+
295
+ For variation benchmarks:
296
+
297
+ ```bash
298
+ python -m featurevisor benchmark \
299
+ --projectDirectoryPath=/path/to/featurevisor-project \
300
+ --environment=production \
301
+ --feature=my_feature \
302
+ --variation \
303
+ --context='{"userId":"123"}'
304
+ ```
305
+
306
+ For variable benchmarks:
307
+
308
+ ```bash
309
+ python -m featurevisor benchmark \
310
+ --projectDirectoryPath=/path/to/featurevisor-project \
311
+ --environment=production \
312
+ --feature=my_feature \
313
+ --variable=my_variable_key \
314
+ --context='{"userId":"123"}'
315
+ ```
316
+
317
+ ### Assess Distribution
318
+
319
+ Inspect enabled/disabled and variation distribution over repeated evaluations:
320
+
321
+ ```bash
322
+ python -m featurevisor assess-distribution \
323
+ --projectDirectoryPath=/path/to/featurevisor-project \
324
+ --environment=production \
325
+ --feature=my_feature \
326
+ --context='{"country":"nl"}' \
327
+ --n=1000
328
+ ```
329
+
330
+ You can also populate UUID-based context keys per iteration:
331
+
332
+ ```bash
333
+ python -m featurevisor assess-distribution \
334
+ --projectDirectoryPath=/path/to/featurevisor-project \
335
+ --environment=production \
336
+ --feature=my_feature \
337
+ --populateUuid=userId \
338
+ --populateUuid=deviceId
339
+ ```
340
+
341
+ <!-- FEATUREVISOR_DOCS_BEGIN -->
342
+
343
+ ## Development
344
+
345
+ This repository assumes:
346
+
347
+ - Python 3.10+
348
+ - Node.js with `npx`
349
+ - Access to a Featurevisor project for CLI and tester integration
350
+
351
+ Run the local test suite:
352
+
353
+ ```bash
354
+ make test
355
+ ```
356
+
357
+ Run the example project integration directly:
358
+
359
+ ```bash
360
+ PYTHONPATH=src python3 -m featurevisor test \
361
+ --projectDirectoryPath=/path/to/featurevisor-project
362
+ ```
363
+
364
+ ## Releasing
365
+
366
+ - Update version in pyproject.toml
367
+ - Push commit to main branch
368
+ - Wait for CI to complete
369
+ - Tag the release with the version number `vX.X.X`
370
+ - This will trigger a new release to PyPI
371
+
372
+ ## License
373
+
374
+ MIT © [Fahad Heylaal](https://fahad19.com)