fb-python-sdk 1.2.0__tar.gz → 1.2.2__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.
- {fb_python_sdk-1.2.0/fb_python_sdk.egg-info → fb_python_sdk-1.2.2}/PKG-INFO +51 -34
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/README.md +38 -3
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/__init__.py +2 -2
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/category.py +4 -4
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/client.py +137 -62
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/common_types.py +107 -79
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/config.py +115 -76
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/data_storage.py +21 -12
- fb_python_sdk-1.2.2/fbclient/evaluator.py +315 -0
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/event_processor.py +64 -33
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/event_types.py +29 -24
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/flag_change_notification.py +55 -33
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/interfaces.py +18 -11
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/notice_broadcaster.py +18 -12
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/status.py +26 -11
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/status_types.py +18 -12
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/streaming.py +166 -93
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/update_processor.py +7 -2
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/utils/__init__.py +47 -26
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/utils/exponential_backoff_jitter_strategy.py +14 -8
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/utils/http_client.py +48 -34
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/utils/repeatable_task.py +13 -5
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/utils/rwlock.py +7 -7
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/fbclient/utils/variation_splitting_algorithm.py +6 -4
- fb_python_sdk-1.2.2/pyproject.toml +94 -0
- fb_python_sdk-1.2.2/pyproject.toml.orig +61 -0
- fb_python_sdk-1.2.2/pytest.ini +5 -0
- fb_python_sdk-1.2.2/tests/__init__.py +0 -0
- fb_python_sdk-1.2.2/tests/fbclient_test_data.json +716 -0
- fb_python_sdk-1.2.2/tests/test_archived_data_sync.py +75 -0
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/tests/test_data_storage.py +12 -2
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/tests/test_data_update_status_provider.py +20 -7
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/tests/test_evaluator.py +14 -6
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/tests/test_event_processor.py +29 -18
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/tests/test_fbclient.py +94 -54
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/tests/test_flag_change_notification.py +10 -9
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/tests/test_insights_enabled.py +81 -51
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/tests/test_runtime_safety.py +110 -86
- fb_python_sdk-1.2.0/MANIFEST.in +0 -4
- fb_python_sdk-1.2.0/PKG-INFO +0 -336
- fb_python_sdk-1.2.0/dev-requirements.txt +0 -10
- fb_python_sdk-1.2.0/fb_python_sdk.egg-info/SOURCES.txt +0 -43
- fb_python_sdk-1.2.0/fb_python_sdk.egg-info/dependency_links.txt +0 -1
- fb_python_sdk-1.2.0/fb_python_sdk.egg-info/requires.txt +0 -16
- fb_python_sdk-1.2.0/fb_python_sdk.egg-info/top_level.txt +0 -1
- fb_python_sdk-1.2.0/fbclient/evaluator.py +0 -305
- fb_python_sdk-1.2.0/pyproject.toml +0 -3
- fb_python_sdk-1.2.0/release/package.json +0 -3
- fb_python_sdk-1.2.0/requirements.txt +0 -4
- fb_python_sdk-1.2.0/setup.cfg +0 -4
- fb_python_sdk-1.2.0/setup.py +0 -57
- {fb_python_sdk-1.2.0 → fb_python_sdk-1.2.2}/LICENSE +0 -0
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fb-python-sdk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Summary: A Python SDK for FeatBit plateform
|
|
5
|
-
Home-page: https://github.com/featbit/featbit-python-sdk
|
|
6
5
|
Author: Dian SUN
|
|
7
|
-
Author-email: featbit.master@gmail.com
|
|
8
|
-
|
|
9
|
-
Project-URL: Issue tracker, https://github.com/featbit/featbit/issues
|
|
6
|
+
Author-email: Dian SUN <featbit.master@gmail.com>
|
|
7
|
+
License-File: LICENSE
|
|
10
8
|
Classifier: Development Status :: 5 - Production/Stable
|
|
11
9
|
Classifier: Intended Audience :: Developers
|
|
12
10
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
@@ -18,36 +16,20 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.12
|
|
19
17
|
Classifier: Programming Language :: Python :: 3.13
|
|
20
18
|
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
-
Requires-Python: >=3.10, <3.15
|
|
22
|
-
Description-Content-Type: text/markdown
|
|
23
|
-
License-File: LICENSE
|
|
24
19
|
Requires-Dist: certifi>=2018.4.16
|
|
25
|
-
Requires-Dist: urllib3<3,>=1.26.5
|
|
26
20
|
Requires-Dist: python-dateutil>=2.8.2
|
|
21
|
+
Requires-Dist: urllib3>=1.26.5,<3
|
|
27
22
|
Requires-Dist: websocket-client>=1.0.0
|
|
23
|
+
Requires-Dist: build ; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest ; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-mock ; extra == 'dev'
|
|
26
|
+
Requires-Dist: twine ; extra == 'dev'
|
|
27
|
+
Requires-Python: >=3.10, <3.15
|
|
28
|
+
Project-URL: Homepage, https://github.com/featbit/featbit-python-sdk
|
|
29
|
+
Project-URL: Code, https://github.com/featbit/featbit-python-sdk
|
|
30
|
+
Project-URL: Issue tracker, https://github.com/featbit/featbit/issues
|
|
28
31
|
Provides-Extra: dev
|
|
29
|
-
|
|
30
|
-
Requires-Dist: urllib3<3,>=1.26.5; extra == "dev"
|
|
31
|
-
Requires-Dist: websocket-client>=1.0.0; extra == "dev"
|
|
32
|
-
Requires-Dist: python-dateutil>=2.8.2; extra == "dev"
|
|
33
|
-
Requires-Dist: flake8; extra == "dev"
|
|
34
|
-
Requires-Dist: pytest; extra == "dev"
|
|
35
|
-
Requires-Dist: pytest-mock; extra == "dev"
|
|
36
|
-
Requires-Dist: autopep8; extra == "dev"
|
|
37
|
-
Requires-Dist: build; extra == "dev"
|
|
38
|
-
Requires-Dist: twine; extra == "dev"
|
|
39
|
-
Dynamic: author
|
|
40
|
-
Dynamic: author-email
|
|
41
|
-
Dynamic: classifier
|
|
42
|
-
Dynamic: description
|
|
43
|
-
Dynamic: description-content-type
|
|
44
|
-
Dynamic: home-page
|
|
45
|
-
Dynamic: license-file
|
|
46
|
-
Dynamic: project-url
|
|
47
|
-
Dynamic: provides-extra
|
|
48
|
-
Dynamic: requires-dist
|
|
49
|
-
Dynamic: requires-python
|
|
50
|
-
Dynamic: summary
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
51
33
|
|
|
52
34
|
# FeatBit Server-Side SDK for Python
|
|
53
35
|
|
|
@@ -75,11 +57,19 @@ If you want to use your own data source, see [Offline Mode](#offline-mode).
|
|
|
75
57
|
## Get Started
|
|
76
58
|
|
|
77
59
|
### Installation
|
|
78
|
-
|
|
60
|
+
This version of the SDK is compatible with Python 3.10 through 3.14.
|
|
79
61
|
CI is configured to test compatibility on Linux and Windows through Python 3.14,
|
|
80
62
|
including the full unit suite and SDK resource-lifecycle audit.
|
|
81
63
|
Free-threaded CPython 3.14 builds are not currently tested or supported.
|
|
82
64
|
|
|
65
|
+
In a uv project, add the SDK with:
|
|
66
|
+
|
|
67
|
+
```shell
|
|
68
|
+
uv add fb-python-sdk
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
To install the published SDK with pip:
|
|
72
|
+
|
|
83
73
|
```shell
|
|
84
74
|
pip install fb-python-sdk
|
|
85
75
|
```
|
|
@@ -134,7 +124,7 @@ shutdown, public runtime exception isolation, and redundant code. Run the
|
|
|
134
124
|
local resource audit with:
|
|
135
125
|
|
|
136
126
|
```shell
|
|
137
|
-
python scripts/resource_audit.py --evaluations 80000 --workers 8
|
|
127
|
+
uv run python scripts/resource_audit.py --evaluations 80000 --workers 8
|
|
138
128
|
```
|
|
139
129
|
|
|
140
130
|
To verify WebSocket synchronization, remote evaluation, status changes, event
|
|
@@ -142,7 +132,7 @@ delivery, and clean shutdown against FeatBit Cloud or a self-hosted evaluation
|
|
|
142
132
|
service, set `FEATBIT_ENV_SECRET` and run:
|
|
143
133
|
|
|
144
134
|
```shell
|
|
145
|
-
python scripts/live_integration_check.py
|
|
135
|
+
uv run python scripts/live_integration_check.py
|
|
146
136
|
```
|
|
147
137
|
|
|
148
138
|
The live script never prints or persists the environment secret. See the
|
|
@@ -325,6 +315,33 @@ client.track_metric(user, event_name, numeric_value);
|
|
|
325
315
|
Make sure `track_metric` is called after the related feature flag is evaluated by simply calling `variation` or `variation_detail`
|
|
326
316
|
otherwise, the custom event may not be included into the experiment result.
|
|
327
317
|
|
|
318
|
+
## Development
|
|
319
|
+
|
|
320
|
+
From the repository root, use [uv](https://docs.astral.sh/uv/getting-started/installation/)
|
|
321
|
+
to sync the locked dependencies and run the project checks:
|
|
322
|
+
|
|
323
|
+
```shell
|
|
324
|
+
uv sync --locked
|
|
325
|
+
uv run ruff check .
|
|
326
|
+
uv run ruff format --check .
|
|
327
|
+
uv run python -m pytest
|
|
328
|
+
uv build
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Apply lint fixes and format the Python files with
|
|
332
|
+
`uv run ruff check --fix .` and `uv run ruff format .`.
|
|
333
|
+
|
|
334
|
+
Enable the Git hook once per clone with `uv run --locked pre-commit install`.
|
|
335
|
+
Before each commit, the hook runs Ruff lint, Ruff format, and the full pytest
|
|
336
|
+
suite in that order. If formatting changes a file, stage the changes and
|
|
337
|
+
retry the commit.
|
|
338
|
+
|
|
339
|
+
Set the release version with `uv version <version>`, which updates
|
|
340
|
+
`pyproject.toml` and `uv.lock`. Update `release/description.md` with the release
|
|
341
|
+
notes. After a push to `main` or `master`, GitHub Actions builds and checks the
|
|
342
|
+
distributions. A required reviewer must approve the `py-production` deployment
|
|
343
|
+
in Actions before the workflow creates the GitHub Release and publishes to PyPI.
|
|
344
|
+
|
|
328
345
|
## Getting support
|
|
329
346
|
|
|
330
347
|
- If you have a specific question about using this sdk, we encourage you
|
|
@@ -24,11 +24,19 @@ If you want to use your own data source, see [Offline Mode](#offline-mode).
|
|
|
24
24
|
## Get Started
|
|
25
25
|
|
|
26
26
|
### Installation
|
|
27
|
-
|
|
27
|
+
This version of the SDK is compatible with Python 3.10 through 3.14.
|
|
28
28
|
CI is configured to test compatibility on Linux and Windows through Python 3.14,
|
|
29
29
|
including the full unit suite and SDK resource-lifecycle audit.
|
|
30
30
|
Free-threaded CPython 3.14 builds are not currently tested or supported.
|
|
31
31
|
|
|
32
|
+
In a uv project, add the SDK with:
|
|
33
|
+
|
|
34
|
+
```shell
|
|
35
|
+
uv add fb-python-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
To install the published SDK with pip:
|
|
39
|
+
|
|
32
40
|
```shell
|
|
33
41
|
pip install fb-python-sdk
|
|
34
42
|
```
|
|
@@ -83,7 +91,7 @@ shutdown, public runtime exception isolation, and redundant code. Run the
|
|
|
83
91
|
local resource audit with:
|
|
84
92
|
|
|
85
93
|
```shell
|
|
86
|
-
python scripts/resource_audit.py --evaluations 80000 --workers 8
|
|
94
|
+
uv run python scripts/resource_audit.py --evaluations 80000 --workers 8
|
|
87
95
|
```
|
|
88
96
|
|
|
89
97
|
To verify WebSocket synchronization, remote evaluation, status changes, event
|
|
@@ -91,7 +99,7 @@ delivery, and clean shutdown against FeatBit Cloud or a self-hosted evaluation
|
|
|
91
99
|
service, set `FEATBIT_ENV_SECRET` and run:
|
|
92
100
|
|
|
93
101
|
```shell
|
|
94
|
-
python scripts/live_integration_check.py
|
|
102
|
+
uv run python scripts/live_integration_check.py
|
|
95
103
|
```
|
|
96
104
|
|
|
97
105
|
The live script never prints or persists the environment secret. See the
|
|
@@ -274,6 +282,33 @@ client.track_metric(user, event_name, numeric_value);
|
|
|
274
282
|
Make sure `track_metric` is called after the related feature flag is evaluated by simply calling `variation` or `variation_detail`
|
|
275
283
|
otherwise, the custom event may not be included into the experiment result.
|
|
276
284
|
|
|
285
|
+
## Development
|
|
286
|
+
|
|
287
|
+
From the repository root, use [uv](https://docs.astral.sh/uv/getting-started/installation/)
|
|
288
|
+
to sync the locked dependencies and run the project checks:
|
|
289
|
+
|
|
290
|
+
```shell
|
|
291
|
+
uv sync --locked
|
|
292
|
+
uv run ruff check .
|
|
293
|
+
uv run ruff format --check .
|
|
294
|
+
uv run python -m pytest
|
|
295
|
+
uv build
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Apply lint fixes and format the Python files with
|
|
299
|
+
`uv run ruff check --fix .` and `uv run ruff format .`.
|
|
300
|
+
|
|
301
|
+
Enable the Git hook once per clone with `uv run --locked pre-commit install`.
|
|
302
|
+
Before each commit, the hook runs Ruff lint, Ruff format, and the full pytest
|
|
303
|
+
suite in that order. If formatting changes a file, stage the changes and
|
|
304
|
+
retry the commit.
|
|
305
|
+
|
|
306
|
+
Set the release version with `uv version <version>`, which updates
|
|
307
|
+
`pyproject.toml` and `uv.lock`. Update `release/description.md` with the release
|
|
308
|
+
notes. After a push to `main` or `master`, GitHub Actions builds and checks the
|
|
309
|
+
distributions. A required reviewer must approve the `py-production` deployment
|
|
310
|
+
in Actions before the workflow creates the GitHub Release and publishes to PyPI.
|
|
311
|
+
|
|
277
312
|
## Getting support
|
|
278
313
|
|
|
279
314
|
- If you have a specific question about using this sdk, we encourage you
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from fbclient.client import FBClient
|
|
2
2
|
from fbclient.config import Config
|
|
3
|
-
from fbclient.utils.rwlock import ReadWriteLock
|
|
4
3
|
from fbclient.utils import log
|
|
4
|
+
from fbclient.utils.rwlock import ReadWriteLock
|
|
5
5
|
|
|
6
6
|
"""Settings."""
|
|
7
7
|
start_wait = 15
|
|
@@ -61,7 +61,7 @@ def set_config(config: Config):
|
|
|
61
61
|
__lock.write_lock()
|
|
62
62
|
if __client:
|
|
63
63
|
__client.stop()
|
|
64
|
-
log.info(
|
|
64
|
+
log.info("FB Python SDK: FB Python Client is reinitializing...")
|
|
65
65
|
__client = FBClient(config, start_wait)
|
|
66
66
|
finally:
|
|
67
67
|
__config = config
|
|
@@ -19,11 +19,11 @@ class Category:
|
|
|
19
19
|
return self._tag
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
FEATURE_FLAGS = Category(
|
|
22
|
+
FEATURE_FLAGS = Category("featureFlags", "ff")
|
|
23
23
|
|
|
24
|
-
SEGMENTS = Category(
|
|
24
|
+
SEGMENTS = Category("segments", "seg")
|
|
25
25
|
|
|
26
|
-
DATATEST = Category(
|
|
26
|
+
DATATEST = Category("datatest", "test")
|
|
27
27
|
|
|
28
28
|
"""
|
|
29
29
|
An enumeration of all supported types. Applications should not need to reference this object directly.
|
|
@@ -31,4 +31,4 @@ Custom data storage implementations can determine what kinds of model objects ma
|
|
|
31
31
|
"""
|
|
32
32
|
ALL_CATS = [FEATURE_FLAGS, SEGMENTS, DATATEST]
|
|
33
33
|
|
|
34
|
-
ALL_CAT_NAMES = [
|
|
34
|
+
ALL_CAT_NAMES = ["featureFlags", "segments", "datatest"]
|
|
@@ -3,13 +3,16 @@ import threading
|
|
|
3
3
|
from typing import Any, Mapping, Optional, Tuple
|
|
4
4
|
|
|
5
5
|
from fbclient.category import FEATURE_FLAGS, SEGMENTS
|
|
6
|
-
from fbclient.common_types import
|
|
7
|
-
_EvalResult)
|
|
6
|
+
from fbclient.common_types import AllFlagStates, EvalDetail, FBUser, _EvalResult
|
|
8
7
|
from fbclient.config import Config
|
|
9
8
|
from fbclient.data_storage import NullDataStorage
|
|
10
|
-
from fbclient.evaluator import (
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
from fbclient.evaluator import (
|
|
10
|
+
REASON_CLIENT_NOT_READY,
|
|
11
|
+
REASON_ERROR,
|
|
12
|
+
REASON_FLAG_NOT_FOUND,
|
|
13
|
+
REASON_USER_NOT_SPECIFIED,
|
|
14
|
+
Evaluator,
|
|
15
|
+
)
|
|
13
16
|
from fbclient.event_processor import DefaultEventProcessor, NullEventProcessor
|
|
14
17
|
from fbclient.event_types import FlagEvent, Metric, MetricEvent, UserEvent
|
|
15
18
|
from fbclient.flag_change_notification import FlagTracker
|
|
@@ -19,8 +22,13 @@ from fbclient.status import DataUpdateStatusProviderImpl
|
|
|
19
22
|
from fbclient.status_types import State
|
|
20
23
|
from fbclient.streaming import Streaming, _data_to_dict
|
|
21
24
|
from fbclient.update_processor import NullUpdateProcessor
|
|
22
|
-
from fbclient.utils import (
|
|
23
|
-
|
|
25
|
+
from fbclient.utils import (
|
|
26
|
+
cast_variation_by_flag_type,
|
|
27
|
+
check_uwsgi,
|
|
28
|
+
log,
|
|
29
|
+
simple_type_inference,
|
|
30
|
+
valide_all_data,
|
|
31
|
+
)
|
|
24
32
|
from fbclient.utils.http_client import DefaultSender
|
|
25
33
|
|
|
26
34
|
|
|
@@ -35,7 +43,7 @@ class FBClient:
|
|
|
35
43
|
Client instances are thread-safe.
|
|
36
44
|
"""
|
|
37
45
|
|
|
38
|
-
def __init__(self, config: Config, start_wait: float = 15.):
|
|
46
|
+
def __init__(self, config: Config, start_wait: float = 15.0):
|
|
39
47
|
"""
|
|
40
48
|
Creates a new client to connect to feature flag center with a specified configuration.
|
|
41
49
|
|
|
@@ -88,22 +96,36 @@ class FBClient:
|
|
|
88
96
|
# data storage
|
|
89
97
|
self._data_storage = config.data_storage
|
|
90
98
|
# evaluator
|
|
91
|
-
self._evaluator = Evaluator(
|
|
92
|
-
|
|
99
|
+
self._evaluator = Evaluator(
|
|
100
|
+
lambda key: self._data_storage.get(FEATURE_FLAGS, key),
|
|
101
|
+
lambda key: self._data_storage.get(SEGMENTS, key),
|
|
102
|
+
)
|
|
93
103
|
# data updator and status provider
|
|
94
104
|
self._update_status_provider = DataUpdateStatusProviderImpl(config.data_storage)
|
|
95
105
|
# update processor
|
|
96
106
|
update_processor_ready = threading.Event()
|
|
97
|
-
self._update_processor = self._build_update_processor(
|
|
107
|
+
self._update_processor = self._build_update_processor(
|
|
108
|
+
config,
|
|
109
|
+
self._broadcaster,
|
|
110
|
+
self._update_status_provider,
|
|
111
|
+
update_processor_ready,
|
|
112
|
+
)
|
|
98
113
|
self._update_processor.start()
|
|
99
114
|
|
|
100
115
|
if start_wait > 0:
|
|
101
116
|
if not isinstance(self._update_processor, NullUpdateProcessor):
|
|
102
|
-
log.info(
|
|
117
|
+
log.info(
|
|
118
|
+
"FB Python SDK: Waiting for Client initialization in %s seconds"
|
|
119
|
+
% str(start_wait)
|
|
120
|
+
)
|
|
103
121
|
|
|
104
122
|
update_processor_ready.wait(start_wait)
|
|
105
|
-
if isinstance(self._data_storage, NullDataStorage) or (
|
|
106
|
-
|
|
123
|
+
if isinstance(self._data_storage, NullDataStorage) or (
|
|
124
|
+
not self._data_storage.initialized and not self._config.is_offline
|
|
125
|
+
):
|
|
126
|
+
log.warning(
|
|
127
|
+
"FB Python SDK: SDK just returns default variation because of no data found in the given environment"
|
|
128
|
+
)
|
|
107
129
|
if not self._update_processor.initialized:
|
|
108
130
|
log.warning("FB Python SDK: SDK was not successfully initialized")
|
|
109
131
|
else:
|
|
@@ -111,25 +133,49 @@ class FBClient:
|
|
|
111
133
|
|
|
112
134
|
def _build_event_processor(self, config: Config):
|
|
113
135
|
if config.event_processor_imp:
|
|
114
|
-
log.debug(
|
|
115
|
-
|
|
136
|
+
log.debug(
|
|
137
|
+
"Using user-specified event processor: %s"
|
|
138
|
+
% str(config.event_processor_imp)
|
|
139
|
+
)
|
|
140
|
+
return config.event_processor_imp(
|
|
141
|
+
config, DefaultSender("insight", config, max_size=10)
|
|
142
|
+
)
|
|
116
143
|
|
|
117
144
|
if config.is_offline:
|
|
118
145
|
log.debug("Offline mode, SDK disable event processing")
|
|
119
|
-
return NullEventProcessor(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
146
|
+
return NullEventProcessor(
|
|
147
|
+
config, DefaultSender("insight", config, max_size=10)
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
return DefaultEventProcessor(
|
|
151
|
+
config, DefaultSender("insight", config, max_size=10)
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
def _build_update_processor(
|
|
155
|
+
self,
|
|
156
|
+
config: Config,
|
|
157
|
+
broadcaster: NoticeBroadcater,
|
|
158
|
+
update_status_provider,
|
|
159
|
+
update_processor_event,
|
|
160
|
+
):
|
|
124
161
|
if config.update_processor_imp:
|
|
125
|
-
log.debug(
|
|
126
|
-
|
|
162
|
+
log.debug(
|
|
163
|
+
"Using user-specified update processor: %s"
|
|
164
|
+
% str(config.update_processor_imp)
|
|
165
|
+
)
|
|
166
|
+
return config.update_processor_imp(
|
|
167
|
+
config, update_status_provider, update_processor_event
|
|
168
|
+
)
|
|
127
169
|
|
|
128
170
|
if config.is_offline:
|
|
129
171
|
log.debug("Offline mode, SDK disable streaming data updating")
|
|
130
|
-
return NullUpdateProcessor(
|
|
172
|
+
return NullUpdateProcessor(
|
|
173
|
+
config, update_status_provider, update_processor_event
|
|
174
|
+
)
|
|
131
175
|
|
|
132
|
-
return Streaming(
|
|
176
|
+
return Streaming(
|
|
177
|
+
config, broadcaster, update_status_provider, update_processor_event
|
|
178
|
+
)
|
|
133
179
|
|
|
134
180
|
def _send_event_safely(self, event):
|
|
135
181
|
try:
|
|
@@ -140,7 +186,7 @@ class FBClient:
|
|
|
140
186
|
except Exception:
|
|
141
187
|
# Event delivery must never affect the application request that
|
|
142
188
|
# produced the event, including when a custom processor is used.
|
|
143
|
-
log.exception(
|
|
189
|
+
log.exception("FB Python SDK: event processor failed")
|
|
144
190
|
|
|
145
191
|
@property
|
|
146
192
|
def initialize(self) -> bool:
|
|
@@ -198,14 +244,15 @@ class FBClient:
|
|
|
198
244
|
# one extension failure cannot prevent the remaining resources
|
|
199
245
|
# from being released or escape into application shutdown code.
|
|
200
246
|
for name, component in (
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
247
|
+
("update processor", self._update_processor),
|
|
248
|
+
("event processor", self._event_processor),
|
|
249
|
+
("notice broadcaster", self._broadcaster),
|
|
250
|
+
("data storage", self._data_storage),
|
|
251
|
+
):
|
|
205
252
|
try:
|
|
206
253
|
component.stop()
|
|
207
254
|
except Exception:
|
|
208
|
-
log.exception(
|
|
255
|
+
log.exception("FB Python SDK: %s failed to stop" % name)
|
|
209
256
|
finally:
|
|
210
257
|
with self._stop_lock:
|
|
211
258
|
self._stop_owner = None
|
|
@@ -218,50 +265,70 @@ class FBClient:
|
|
|
218
265
|
self.stop()
|
|
219
266
|
|
|
220
267
|
def is_offline(self) -> bool:
|
|
221
|
-
"""Returns true if the client is in offline mode.
|
|
222
|
-
"""
|
|
268
|
+
"""Returns true if the client is in offline mode."""
|
|
223
269
|
return self._config.is_offline
|
|
224
270
|
|
|
225
271
|
def _get_flag_internal(self, key: str) -> Optional[dict]:
|
|
226
272
|
return self._data_storage.get(FEATURE_FLAGS, key)
|
|
227
273
|
|
|
228
|
-
def __handle_default_value(
|
|
274
|
+
def __handle_default_value(
|
|
275
|
+
self, key: str, default: Any
|
|
276
|
+
) -> Tuple[Optional[str], Any]:
|
|
229
277
|
default_value = self._config.get_default_value(key, default)
|
|
230
278
|
try:
|
|
231
279
|
default_value_type = simple_type_inference(default_value)
|
|
232
280
|
if default_value is None:
|
|
233
281
|
return None, None
|
|
234
|
-
elif default_value_type ==
|
|
282
|
+
elif default_value_type == "boolean":
|
|
235
283
|
return default_value_type, str(default_value).lower()
|
|
236
|
-
elif default_value_type ==
|
|
284
|
+
elif default_value_type == "json":
|
|
237
285
|
return default_value_type, json.dumps(default_value)
|
|
238
286
|
else:
|
|
239
287
|
return default_value_type, str(default_value)
|
|
240
288
|
except Exception:
|
|
241
|
-
log.warning(
|
|
289
|
+
log.warning(
|
|
290
|
+
"FB Python SDK: unsupported default value; returning it unchanged on evaluation failure"
|
|
291
|
+
)
|
|
242
292
|
return None, default_value
|
|
243
293
|
|
|
244
|
-
def _evaluate_internal(
|
|
294
|
+
def _evaluate_internal(
|
|
295
|
+
self, key: str, user: dict, default: Any = None
|
|
296
|
+
) -> _EvalResult:
|
|
245
297
|
default_value_type, default_value = self.__handle_default_value(key, default)
|
|
246
298
|
try:
|
|
247
299
|
if not self.initialize:
|
|
248
|
-
log.warning(
|
|
249
|
-
|
|
300
|
+
log.warning(
|
|
301
|
+
"FB Python SDK: Evaluation called before SDK is initialized for feature flag, well using the default value"
|
|
302
|
+
)
|
|
303
|
+
return _EvalResult.error(
|
|
304
|
+
default_value, REASON_CLIENT_NOT_READY, key, default_value_type
|
|
305
|
+
)
|
|
250
306
|
|
|
251
307
|
if not key:
|
|
252
|
-
log.warning(
|
|
253
|
-
|
|
308
|
+
log.warning(
|
|
309
|
+
"FB Python SDK: null feature flag key; returning default value"
|
|
310
|
+
)
|
|
311
|
+
return _EvalResult.error(
|
|
312
|
+
default_value, REASON_FLAG_NOT_FOUND, key, default_value_type
|
|
313
|
+
)
|
|
254
314
|
|
|
255
315
|
flag = self._get_flag_internal(key)
|
|
256
316
|
if not flag:
|
|
257
|
-
log.warning(
|
|
258
|
-
|
|
317
|
+
log.warning(
|
|
318
|
+
"FB Python SDK: Unknown feature flag %s; returning default value"
|
|
319
|
+
% key
|
|
320
|
+
)
|
|
321
|
+
return _EvalResult.error(
|
|
322
|
+
default_value, REASON_FLAG_NOT_FOUND, key, default_value_type
|
|
323
|
+
)
|
|
259
324
|
|
|
260
325
|
try:
|
|
261
326
|
fb_user = FBUser.from_dict(user)
|
|
262
327
|
except ValueError as ve:
|
|
263
|
-
log.warning(
|
|
264
|
-
return _EvalResult.error(
|
|
328
|
+
log.warning("FB Python SDK: %s" % str(ve))
|
|
329
|
+
return _EvalResult.error(
|
|
330
|
+
default_value, REASON_USER_NOT_SPECIFIED, key, default_value_type
|
|
331
|
+
)
|
|
265
332
|
|
|
266
333
|
fb_event = FlagEvent(fb_user)
|
|
267
334
|
er = self._evaluator.evaluate(flag, fb_user, fb_event)
|
|
@@ -269,8 +336,10 @@ class FBClient:
|
|
|
269
336
|
return er
|
|
270
337
|
|
|
271
338
|
except Exception as e:
|
|
272
|
-
log.exception(
|
|
273
|
-
return _EvalResult.error(
|
|
339
|
+
log.exception("FB Python SDK: unexpected error in evaluation: %s" % str(e))
|
|
340
|
+
return _EvalResult.error(
|
|
341
|
+
default_value, REASON_ERROR, key, default_value_type
|
|
342
|
+
)
|
|
274
343
|
|
|
275
344
|
def variation(self, key: str, user: dict, default: Any = None) -> Any:
|
|
276
345
|
"""Return the variation of a feature flag for a given user.
|
|
@@ -296,7 +365,7 @@ class FBClient:
|
|
|
296
365
|
return cast_variation_by_flag_type(er.flag_type, er.value)
|
|
297
366
|
|
|
298
367
|
def variation_detail(self, key: str, user: dict, default: Any = None) -> EvalDetail:
|
|
299
|
-
""""Return the variation of a feature flag for a given user, but also provides additional information
|
|
368
|
+
""" "Return the variation of a feature flag for a given user, but also provides additional information
|
|
300
369
|
about how this value was calculated, in the property `data` of the :class:`fbclient.common_types.EvalDetail`.
|
|
301
370
|
|
|
302
371
|
This method collects an evaluation event if evaluation succeeds and insights are enabled for the flag.
|
|
@@ -326,7 +395,9 @@ class FBClient:
|
|
|
326
395
|
success = True
|
|
327
396
|
try:
|
|
328
397
|
if not self.initialize:
|
|
329
|
-
log.warning(
|
|
398
|
+
log.warning(
|
|
399
|
+
"FB Python SDK: Evaluation called before Java SDK client initialized for feature flag"
|
|
400
|
+
)
|
|
330
401
|
reason = REASON_CLIENT_NOT_READY
|
|
331
402
|
success = False
|
|
332
403
|
else:
|
|
@@ -338,13 +409,13 @@ class FBClient:
|
|
|
338
409
|
er = self._evaluator.evaluate(flag, fb_user, fb_event)
|
|
339
410
|
all_flag_details[er.to_evail_detail] = fb_event
|
|
340
411
|
except ValueError as ve:
|
|
341
|
-
log.warning(
|
|
412
|
+
log.warning("FB Python SDK: %s" % str(ve))
|
|
342
413
|
reason = REASON_USER_NOT_SPECIFIED
|
|
343
414
|
success = False
|
|
344
415
|
except:
|
|
345
416
|
raise
|
|
346
417
|
except Exception as e:
|
|
347
|
-
log.exception(
|
|
418
|
+
log.exception("FB Python SDK: unexpected error in evaluation: %s" % str(e))
|
|
348
419
|
reason = REASON_ERROR
|
|
349
420
|
success = False
|
|
350
421
|
return AllFlagStates(success, reason, all_flag_details, self._event_handler)
|
|
@@ -358,11 +429,15 @@ class FBClient:
|
|
|
358
429
|
"""
|
|
359
430
|
try:
|
|
360
431
|
if not self.initialize:
|
|
361
|
-
log.warning(
|
|
432
|
+
log.warning(
|
|
433
|
+
"FB Python SDK: isFlagKnown called before SDK is initialized for feature flag"
|
|
434
|
+
)
|
|
362
435
|
return False
|
|
363
436
|
return self._get_flag_internal(key) is not None
|
|
364
437
|
except Exception as e:
|
|
365
|
-
log.exception(
|
|
438
|
+
log.exception(
|
|
439
|
+
"FB Python SDK: unexpected error in is_flag_known: %s" % str(e)
|
|
440
|
+
)
|
|
366
441
|
return False
|
|
367
442
|
|
|
368
443
|
def flush(self):
|
|
@@ -377,7 +452,7 @@ class FBClient:
|
|
|
377
452
|
if not self._closed:
|
|
378
453
|
self._event_processor.flush()
|
|
379
454
|
except Exception:
|
|
380
|
-
log.exception(
|
|
455
|
+
log.exception("FB Python SDK: event processor flush failed")
|
|
381
456
|
|
|
382
457
|
def identify(self, user: dict):
|
|
383
458
|
"""register an end user in the feature flag center
|
|
@@ -387,7 +462,7 @@ class FBClient:
|
|
|
387
462
|
try:
|
|
388
463
|
fb_user = FBUser.from_dict(user)
|
|
389
464
|
except ValueError:
|
|
390
|
-
log.warning(
|
|
465
|
+
log.warning("FB Python SDK: user invalid")
|
|
391
466
|
return
|
|
392
467
|
|
|
393
468
|
self._event_handler(UserEvent(fb_user))
|
|
@@ -403,12 +478,12 @@ class FBClient:
|
|
|
403
478
|
:param metric_value: a numeric value used by the experiment, default value is 1.0
|
|
404
479
|
"""
|
|
405
480
|
if not event_name:
|
|
406
|
-
log.warning(
|
|
481
|
+
log.warning("FB Python SDK: event/metric invalid")
|
|
407
482
|
return
|
|
408
483
|
try:
|
|
409
484
|
fb_user = FBUser.from_dict(user)
|
|
410
485
|
except ValueError:
|
|
411
|
-
log.warning(
|
|
486
|
+
log.warning("FB Python SDK: user invalid")
|
|
412
487
|
return
|
|
413
488
|
|
|
414
489
|
metric_event = MetricEvent(fb_user).add(Metric(event_name, metric_value))
|
|
@@ -423,12 +498,12 @@ class FBClient:
|
|
|
423
498
|
:param metrics: the pairs of event_name and metric_value
|
|
424
499
|
"""
|
|
425
500
|
if not isinstance(metrics, dict):
|
|
426
|
-
log.warning(
|
|
501
|
+
log.warning("FB Python SDK: metrics invalid")
|
|
427
502
|
return
|
|
428
503
|
try:
|
|
429
504
|
fb_user = FBUser.from_dict(user)
|
|
430
505
|
except ValueError:
|
|
431
|
-
log.warning(
|
|
506
|
+
log.warning("FB Python SDK: user invalid")
|
|
432
507
|
return
|
|
433
508
|
|
|
434
509
|
metric_event = MetricEvent(fb_user)
|
|
@@ -447,11 +522,11 @@ class FBClient:
|
|
|
447
522
|
if self._config.is_offline:
|
|
448
523
|
all_data = json.loads(json_str)
|
|
449
524
|
if valide_all_data(all_data):
|
|
450
|
-
version, data = _data_to_dict(all_data[
|
|
525
|
+
version, data = _data_to_dict(all_data["data"])
|
|
451
526
|
if self._update_status_provider.init(data, version):
|
|
452
527
|
self._update_status_provider.update_state(State.ok_state())
|
|
453
528
|
return True
|
|
454
529
|
except Exception:
|
|
455
|
-
log.exception(
|
|
530
|
+
log.exception("FB Python SDK: invalid external bootstrap data")
|
|
456
531
|
|
|
457
532
|
return False
|