fb-python-sdk 1.1.6__tar.gz → 1.1.8__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.1.6 → fb_python_sdk-1.1.8}/MANIFEST.in +1 -1
- {fb_python_sdk-1.1.6/fb_python_sdk.egg-info → fb_python_sdk-1.1.8}/PKG-INFO +54 -4
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/README.md +39 -1
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8/fb_python_sdk.egg-info}/PKG-INFO +54 -4
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fb_python_sdk.egg-info/SOURCES.txt +2 -2
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fb_python_sdk.egg-info/top_level.txt +0 -1
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/__init__.py +0 -3
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/client.py +86 -25
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/common_types.py +12 -3
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/config.py +20 -13
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/data_storage.py +40 -17
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/event_processor.py +81 -30
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/interfaces.py +21 -3
- fb_python_sdk-1.1.8/fbclient/notice_broadcaster.py +85 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/status.py +57 -5
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/streaming.py +95 -19
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/update_processor.py +6 -2
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/utils/__init__.py +3 -3
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/utils/http_client.py +8 -4
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/utils/repeatable_task.py +13 -6
- fb_python_sdk-1.1.8/release/package.json +3 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/setup.py +2 -3
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/tests/test_data_storage.py +33 -1
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/tests/test_data_update_status_provider.py +66 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/tests/test_event_processor.py +75 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/tests/test_fbclient.py +56 -4
- fb_python_sdk-1.1.8/tests/test_runtime_safety.py +472 -0
- fb_python_sdk-1.1.6/fbclient/notice_broadcaster.py +0 -57
- fb_python_sdk-1.1.6/release/package.json +0 -3
- fb_python_sdk-1.1.6/tests/__init__.py +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/LICENSE +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/dev-requirements.txt +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fb_python_sdk.egg-info/dependency_links.txt +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fb_python_sdk.egg-info/requires.txt +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/category.py +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/evaluator.py +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/event_types.py +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/flag_change_notification.py +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/status_types.py +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/utils/exponential_backoff_jitter_strategy.py +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/utils/rwlock.py +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/fbclient/utils/variation_splitting_algorithm.py +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/pyproject.toml +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/requirements.txt +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/setup.cfg +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/tests/test_evaluator.py +0 -0
- {fb_python_sdk-1.1.6 → fb_python_sdk-1.1.8}/tests/test_flag_change_notification.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: fb-python-sdk
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.8
|
|
4
4
|
Summary: A Python SDK for FeatBit plateform
|
|
5
5
|
Home-page: https://github.com/featbit/featbit-python-sdk
|
|
6
6
|
Author: Dian SUN
|
|
@@ -20,7 +20,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.10
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
-
Requires-Python: >=3.6,
|
|
23
|
+
Requires-Python: >=3.6, <3.13
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
Requires-Dist: certifi>=2018.4.16
|
|
@@ -38,6 +38,18 @@ Requires-Dist: pytest-mock; extra == "dev"
|
|
|
38
38
|
Requires-Dist: autopep8; extra == "dev"
|
|
39
39
|
Requires-Dist: build; extra == "dev"
|
|
40
40
|
Requires-Dist: twine; extra == "dev"
|
|
41
|
+
Dynamic: author
|
|
42
|
+
Dynamic: author-email
|
|
43
|
+
Dynamic: classifier
|
|
44
|
+
Dynamic: description
|
|
45
|
+
Dynamic: description-content-type
|
|
46
|
+
Dynamic: home-page
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
Dynamic: project-url
|
|
49
|
+
Dynamic: provides-extra
|
|
50
|
+
Dynamic: requires-dist
|
|
51
|
+
Dynamic: requires-python
|
|
52
|
+
Dynamic: summary
|
|
41
53
|
|
|
42
54
|
# FeatBit Server-Side SDK for Python
|
|
43
55
|
|
|
@@ -59,7 +71,7 @@ If you want to use your own data source, see [Offline Mode](#offline-mode).
|
|
|
59
71
|
## Get Started
|
|
60
72
|
|
|
61
73
|
### Installation
|
|
62
|
-
|
|
74
|
+
Install the SDK using pip. This version is compatible with Python 3.6 through 3.12.
|
|
63
75
|
|
|
64
76
|
```shell
|
|
65
77
|
pip install fb-python-sdk
|
|
@@ -107,6 +119,29 @@ client.stop()
|
|
|
107
119
|
|
|
108
120
|
- [Python Demo](https://github.com/featbit/featbit-samples/blob/main/samples/dino-game/demo-python/demo_python.py)
|
|
109
121
|
|
|
122
|
+
### SDK reliability and live verification
|
|
123
|
+
|
|
124
|
+
The repository includes a repeatable [reliability review](docs/REVIEW.md)
|
|
125
|
+
covering unit tests, thread safety, memory retention, background-thread
|
|
126
|
+
shutdown, public runtime exception isolation, and redundant code. Run the
|
|
127
|
+
local resource audit with:
|
|
128
|
+
|
|
129
|
+
```shell
|
|
130
|
+
python scripts/resource_audit.py --evaluations 80000 --workers 8
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
To verify WebSocket synchronization, remote evaluation, status changes, event
|
|
134
|
+
delivery, and clean shutdown against FeatBit Cloud or a self-hosted evaluation
|
|
135
|
+
service, set `FEATBIT_ENV_SECRET` and run:
|
|
136
|
+
|
|
137
|
+
```shell
|
|
138
|
+
python scripts/live_integration_check.py
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The live script never prints or persists the environment secret. See the
|
|
142
|
+
review document for all supported environment variables and verification
|
|
143
|
+
criteria.
|
|
144
|
+
|
|
110
145
|
### FBClient
|
|
111
146
|
|
|
112
147
|
Applications **SHOULD instantiate a single FBClient instance** for the lifetime of the application. In the case where an application
|
|
@@ -153,6 +188,16 @@ if client.update_status_provider.wait_for_OKState():
|
|
|
153
188
|
|
|
154
189
|
It's possible to set a timeout in seconds for the `wait_for_OKState` method. If the timeout is reached, the method will return `False` and the client will still be in an uninitialized state. If you do not specify a timeout, the method will wait indefinitely.
|
|
155
190
|
|
|
191
|
+
You can also observe later connection interruptions and recoveries:
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
def on_status_change(state):
|
|
195
|
+
print(state.state_type, state.error_track)
|
|
196
|
+
|
|
197
|
+
client.update_status_provider.add_listener(on_status_change)
|
|
198
|
+
# Remove it during application shutdown:
|
|
199
|
+
client.update_status_provider.remove_listener(on_status_change)
|
|
200
|
+
```
|
|
156
201
|
|
|
157
202
|
> To check if the client is ready is optional. Even if the client is not ready, you can still evaluate feature flags, but the default value will be returned if SDK is not yet initialized.
|
|
158
203
|
|
|
@@ -177,6 +222,7 @@ if client.initialize:
|
|
|
177
222
|
flag_value = client.variation(flag_key, user, default_value)
|
|
178
223
|
# evaluate the flag value and get the detail
|
|
179
224
|
detail = client.variation_detail(flag_key, user, default=None)
|
|
225
|
+
print(detail.variation, detail.variation_id, detail.reason)
|
|
180
226
|
```
|
|
181
227
|
|
|
182
228
|
If you would like to get variations of all feature flags in a special environment, you can use `fbclient.client.FBClient.get_all_latest_flag_variations`, SDK will return `fbclient.common_types.AllFlagStates`, that explain the details of all feature flags. `fbclient.common_types.AllFlagStates.get()` returns the detail of a given feature flag key.
|
|
@@ -196,6 +242,10 @@ if client.initialize:
|
|
|
196
242
|
|
|
197
243
|
> **Note**
|
|
198
244
|
> If evaluation happened before the client is initialized, or you provide the wrong flag key/user for evaluation, the `variation` calls will return the default value. The `fbclient.common_types.EvalDetail` will explain the details of the latest evaluation including error reason.
|
|
245
|
+
> Runtime evaluation does not raise solely because a supplied default has an
|
|
246
|
+
> unsupported type. If no flag value can be produced, that default object is
|
|
247
|
+
> returned unchanged and a diagnostic message is logged. Required client
|
|
248
|
+
> configuration remains fail-fast during construction.
|
|
199
249
|
|
|
200
250
|
### Flag Tracking
|
|
201
251
|
|
|
@@ -18,7 +18,7 @@ If you want to use your own data source, see [Offline Mode](#offline-mode).
|
|
|
18
18
|
## Get Started
|
|
19
19
|
|
|
20
20
|
### Installation
|
|
21
|
-
|
|
21
|
+
Install the SDK using pip. This version is compatible with Python 3.6 through 3.12.
|
|
22
22
|
|
|
23
23
|
```shell
|
|
24
24
|
pip install fb-python-sdk
|
|
@@ -66,6 +66,29 @@ client.stop()
|
|
|
66
66
|
|
|
67
67
|
- [Python Demo](https://github.com/featbit/featbit-samples/blob/main/samples/dino-game/demo-python/demo_python.py)
|
|
68
68
|
|
|
69
|
+
### SDK reliability and live verification
|
|
70
|
+
|
|
71
|
+
The repository includes a repeatable [reliability review](docs/REVIEW.md)
|
|
72
|
+
covering unit tests, thread safety, memory retention, background-thread
|
|
73
|
+
shutdown, public runtime exception isolation, and redundant code. Run the
|
|
74
|
+
local resource audit with:
|
|
75
|
+
|
|
76
|
+
```shell
|
|
77
|
+
python scripts/resource_audit.py --evaluations 80000 --workers 8
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
To verify WebSocket synchronization, remote evaluation, status changes, event
|
|
81
|
+
delivery, and clean shutdown against FeatBit Cloud or a self-hosted evaluation
|
|
82
|
+
service, set `FEATBIT_ENV_SECRET` and run:
|
|
83
|
+
|
|
84
|
+
```shell
|
|
85
|
+
python scripts/live_integration_check.py
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The live script never prints or persists the environment secret. See the
|
|
89
|
+
review document for all supported environment variables and verification
|
|
90
|
+
criteria.
|
|
91
|
+
|
|
69
92
|
### FBClient
|
|
70
93
|
|
|
71
94
|
Applications **SHOULD instantiate a single FBClient instance** for the lifetime of the application. In the case where an application
|
|
@@ -112,6 +135,16 @@ if client.update_status_provider.wait_for_OKState():
|
|
|
112
135
|
|
|
113
136
|
It's possible to set a timeout in seconds for the `wait_for_OKState` method. If the timeout is reached, the method will return `False` and the client will still be in an uninitialized state. If you do not specify a timeout, the method will wait indefinitely.
|
|
114
137
|
|
|
138
|
+
You can also observe later connection interruptions and recoveries:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
def on_status_change(state):
|
|
142
|
+
print(state.state_type, state.error_track)
|
|
143
|
+
|
|
144
|
+
client.update_status_provider.add_listener(on_status_change)
|
|
145
|
+
# Remove it during application shutdown:
|
|
146
|
+
client.update_status_provider.remove_listener(on_status_change)
|
|
147
|
+
```
|
|
115
148
|
|
|
116
149
|
> To check if the client is ready is optional. Even if the client is not ready, you can still evaluate feature flags, but the default value will be returned if SDK is not yet initialized.
|
|
117
150
|
|
|
@@ -136,6 +169,7 @@ if client.initialize:
|
|
|
136
169
|
flag_value = client.variation(flag_key, user, default_value)
|
|
137
170
|
# evaluate the flag value and get the detail
|
|
138
171
|
detail = client.variation_detail(flag_key, user, default=None)
|
|
172
|
+
print(detail.variation, detail.variation_id, detail.reason)
|
|
139
173
|
```
|
|
140
174
|
|
|
141
175
|
If you would like to get variations of all feature flags in a special environment, you can use `fbclient.client.FBClient.get_all_latest_flag_variations`, SDK will return `fbclient.common_types.AllFlagStates`, that explain the details of all feature flags. `fbclient.common_types.AllFlagStates.get()` returns the detail of a given feature flag key.
|
|
@@ -155,6 +189,10 @@ if client.initialize:
|
|
|
155
189
|
|
|
156
190
|
> **Note**
|
|
157
191
|
> If evaluation happened before the client is initialized, or you provide the wrong flag key/user for evaluation, the `variation` calls will return the default value. The `fbclient.common_types.EvalDetail` will explain the details of the latest evaluation including error reason.
|
|
192
|
+
> Runtime evaluation does not raise solely because a supplied default has an
|
|
193
|
+
> unsupported type. If no flag value can be produced, that default object is
|
|
194
|
+
> returned unchanged and a diagnostic message is logged. Required client
|
|
195
|
+
> configuration remains fail-fast during construction.
|
|
158
196
|
|
|
159
197
|
### Flag Tracking
|
|
160
198
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: fb-python-sdk
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.8
|
|
4
4
|
Summary: A Python SDK for FeatBit plateform
|
|
5
5
|
Home-page: https://github.com/featbit/featbit-python-sdk
|
|
6
6
|
Author: Dian SUN
|
|
@@ -20,7 +20,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.10
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
-
Requires-Python: >=3.6,
|
|
23
|
+
Requires-Python: >=3.6, <3.13
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
Requires-Dist: certifi>=2018.4.16
|
|
@@ -38,6 +38,18 @@ Requires-Dist: pytest-mock; extra == "dev"
|
|
|
38
38
|
Requires-Dist: autopep8; extra == "dev"
|
|
39
39
|
Requires-Dist: build; extra == "dev"
|
|
40
40
|
Requires-Dist: twine; extra == "dev"
|
|
41
|
+
Dynamic: author
|
|
42
|
+
Dynamic: author-email
|
|
43
|
+
Dynamic: classifier
|
|
44
|
+
Dynamic: description
|
|
45
|
+
Dynamic: description-content-type
|
|
46
|
+
Dynamic: home-page
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
Dynamic: project-url
|
|
49
|
+
Dynamic: provides-extra
|
|
50
|
+
Dynamic: requires-dist
|
|
51
|
+
Dynamic: requires-python
|
|
52
|
+
Dynamic: summary
|
|
41
53
|
|
|
42
54
|
# FeatBit Server-Side SDK for Python
|
|
43
55
|
|
|
@@ -59,7 +71,7 @@ If you want to use your own data source, see [Offline Mode](#offline-mode).
|
|
|
59
71
|
## Get Started
|
|
60
72
|
|
|
61
73
|
### Installation
|
|
62
|
-
|
|
74
|
+
Install the SDK using pip. This version is compatible with Python 3.6 through 3.12.
|
|
63
75
|
|
|
64
76
|
```shell
|
|
65
77
|
pip install fb-python-sdk
|
|
@@ -107,6 +119,29 @@ client.stop()
|
|
|
107
119
|
|
|
108
120
|
- [Python Demo](https://github.com/featbit/featbit-samples/blob/main/samples/dino-game/demo-python/demo_python.py)
|
|
109
121
|
|
|
122
|
+
### SDK reliability and live verification
|
|
123
|
+
|
|
124
|
+
The repository includes a repeatable [reliability review](docs/REVIEW.md)
|
|
125
|
+
covering unit tests, thread safety, memory retention, background-thread
|
|
126
|
+
shutdown, public runtime exception isolation, and redundant code. Run the
|
|
127
|
+
local resource audit with:
|
|
128
|
+
|
|
129
|
+
```shell
|
|
130
|
+
python scripts/resource_audit.py --evaluations 80000 --workers 8
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
To verify WebSocket synchronization, remote evaluation, status changes, event
|
|
134
|
+
delivery, and clean shutdown against FeatBit Cloud or a self-hosted evaluation
|
|
135
|
+
service, set `FEATBIT_ENV_SECRET` and run:
|
|
136
|
+
|
|
137
|
+
```shell
|
|
138
|
+
python scripts/live_integration_check.py
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The live script never prints or persists the environment secret. See the
|
|
142
|
+
review document for all supported environment variables and verification
|
|
143
|
+
criteria.
|
|
144
|
+
|
|
110
145
|
### FBClient
|
|
111
146
|
|
|
112
147
|
Applications **SHOULD instantiate a single FBClient instance** for the lifetime of the application. In the case where an application
|
|
@@ -153,6 +188,16 @@ if client.update_status_provider.wait_for_OKState():
|
|
|
153
188
|
|
|
154
189
|
It's possible to set a timeout in seconds for the `wait_for_OKState` method. If the timeout is reached, the method will return `False` and the client will still be in an uninitialized state. If you do not specify a timeout, the method will wait indefinitely.
|
|
155
190
|
|
|
191
|
+
You can also observe later connection interruptions and recoveries:
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
def on_status_change(state):
|
|
195
|
+
print(state.state_type, state.error_track)
|
|
196
|
+
|
|
197
|
+
client.update_status_provider.add_listener(on_status_change)
|
|
198
|
+
# Remove it during application shutdown:
|
|
199
|
+
client.update_status_provider.remove_listener(on_status_change)
|
|
200
|
+
```
|
|
156
201
|
|
|
157
202
|
> To check if the client is ready is optional. Even if the client is not ready, you can still evaluate feature flags, but the default value will be returned if SDK is not yet initialized.
|
|
158
203
|
|
|
@@ -177,6 +222,7 @@ if client.initialize:
|
|
|
177
222
|
flag_value = client.variation(flag_key, user, default_value)
|
|
178
223
|
# evaluate the flag value and get the detail
|
|
179
224
|
detail = client.variation_detail(flag_key, user, default=None)
|
|
225
|
+
print(detail.variation, detail.variation_id, detail.reason)
|
|
180
226
|
```
|
|
181
227
|
|
|
182
228
|
If you would like to get variations of all feature flags in a special environment, you can use `fbclient.client.FBClient.get_all_latest_flag_variations`, SDK will return `fbclient.common_types.AllFlagStates`, that explain the details of all feature flags. `fbclient.common_types.AllFlagStates.get()` returns the detail of a given feature flag key.
|
|
@@ -196,6 +242,10 @@ if client.initialize:
|
|
|
196
242
|
|
|
197
243
|
> **Note**
|
|
198
244
|
> If evaluation happened before the client is initialized, or you provide the wrong flag key/user for evaluation, the `variation` calls will return the default value. The `fbclient.common_types.EvalDetail` will explain the details of the latest evaluation including error reason.
|
|
245
|
+
> Runtime evaluation does not raise solely because a supplied default has an
|
|
246
|
+
> unsupported type. If no flag value can be produced, that default object is
|
|
247
|
+
> returned unchanged and a diagnostic message is logged. Required client
|
|
248
|
+
> configuration remains fail-fast during construction.
|
|
199
249
|
|
|
200
250
|
### Flag Tracking
|
|
201
251
|
|
|
@@ -33,10 +33,10 @@ fbclient/utils/repeatable_task.py
|
|
|
33
33
|
fbclient/utils/rwlock.py
|
|
34
34
|
fbclient/utils/variation_splitting_algorithm.py
|
|
35
35
|
release/package.json
|
|
36
|
-
tests/__init__.py
|
|
37
36
|
tests/test_data_storage.py
|
|
38
37
|
tests/test_data_update_status_provider.py
|
|
39
38
|
tests/test_evaluator.py
|
|
40
39
|
tests/test_event_processor.py
|
|
41
40
|
tests/test_fbclient.py
|
|
42
|
-
tests/test_flag_change_notification.py
|
|
41
|
+
tests/test_flag_change_notification.py
|
|
42
|
+
tests/test_runtime_safety.py
|
|
@@ -24,9 +24,7 @@ def get() -> FBClient:
|
|
|
24
24
|
If you need to create multiple client instances with different environments, instead of this
|
|
25
25
|
singleton approach you can call directly the :class:`fbclient.client.FBClient` constructor.
|
|
26
26
|
"""
|
|
27
|
-
global __config
|
|
28
27
|
global __client
|
|
29
|
-
global __lock
|
|
30
28
|
|
|
31
29
|
try:
|
|
32
30
|
__lock.read_lock()
|
|
@@ -58,7 +56,6 @@ def set_config(config: Config):
|
|
|
58
56
|
"""
|
|
59
57
|
global __config
|
|
60
58
|
global __client
|
|
61
|
-
global __lock
|
|
62
59
|
|
|
63
60
|
try:
|
|
64
61
|
__lock.write_lock()
|
|
@@ -16,6 +16,7 @@ from fbclient.flag_change_notification import FlagTracker
|
|
|
16
16
|
from fbclient.interfaces import DataUpdateStatusProvider
|
|
17
17
|
from fbclient.notice_broadcaster import NoticeBroadcater
|
|
18
18
|
from fbclient.status import DataUpdateStatusProviderImpl
|
|
19
|
+
from fbclient.status_types import State
|
|
19
20
|
from fbclient.streaming import Streaming, _data_to_dict
|
|
20
21
|
from fbclient.update_processor import NullUpdateProcessor
|
|
21
22
|
from fbclient.utils import (cast_variation_by_flag_type, check_uwsgi, log,
|
|
@@ -68,6 +69,10 @@ class FBClient:
|
|
|
68
69
|
raise ValueError("Config is not valid")
|
|
69
70
|
|
|
70
71
|
self._config = config
|
|
72
|
+
self._stop_lock = threading.Lock()
|
|
73
|
+
self._stop_complete = threading.Event()
|
|
74
|
+
self._stop_owner = None
|
|
75
|
+
self._closed = False
|
|
71
76
|
if self._config.is_offline:
|
|
72
77
|
log.info("FB Python SDK: SDK is in offline mode")
|
|
73
78
|
else:
|
|
@@ -79,7 +84,7 @@ class FBClient:
|
|
|
79
84
|
# init components
|
|
80
85
|
# event processor
|
|
81
86
|
self._event_processor = self._build_event_processor(config)
|
|
82
|
-
self._event_handler =
|
|
87
|
+
self._event_handler = self._send_event_safely
|
|
83
88
|
# data storage
|
|
84
89
|
self._data_storage = config.data_storage
|
|
85
90
|
# evaluator
|
|
@@ -126,6 +131,15 @@ class FBClient:
|
|
|
126
131
|
|
|
127
132
|
return Streaming(config, broadcaster, update_status_provider, update_processor_event)
|
|
128
133
|
|
|
134
|
+
def _send_event_safely(self, event):
|
|
135
|
+
try:
|
|
136
|
+
if not self._closed:
|
|
137
|
+
self._event_processor.send_event(event)
|
|
138
|
+
except Exception:
|
|
139
|
+
# Event delivery must never affect the application request that
|
|
140
|
+
# produced the event, including when a custom processor is used.
|
|
141
|
+
log.exception('FB Python SDK: event processor failed')
|
|
142
|
+
|
|
129
143
|
@property
|
|
130
144
|
def initialize(self) -> bool:
|
|
131
145
|
"""Returns true if the client has successfully connected to feature flag center.
|
|
@@ -154,11 +168,46 @@ class FBClient:
|
|
|
154
168
|
|
|
155
169
|
Do not attempt to use the client after calling this method.
|
|
156
170
|
"""
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
self.
|
|
160
|
-
|
|
161
|
-
|
|
171
|
+
current_thread_id = threading.current_thread().ident
|
|
172
|
+
owns_shutdown = False
|
|
173
|
+
with self._stop_lock:
|
|
174
|
+
if self._closed:
|
|
175
|
+
# A recursive call from a synchronous shutdown callback must
|
|
176
|
+
# return immediately. Unrelated callers wait until the owner
|
|
177
|
+
# has released every SDK resource.
|
|
178
|
+
if self._stop_owner == current_thread_id:
|
|
179
|
+
return
|
|
180
|
+
else:
|
|
181
|
+
self._closed = True
|
|
182
|
+
self._stop_owner = current_thread_id
|
|
183
|
+
owns_shutdown = True
|
|
184
|
+
|
|
185
|
+
if not owns_shutdown:
|
|
186
|
+
self._stop_complete.wait()
|
|
187
|
+
return
|
|
188
|
+
|
|
189
|
+
try:
|
|
190
|
+
# The client was marked closed atomically above. Component
|
|
191
|
+
# shutdown can synchronously publish status changes, and an
|
|
192
|
+
# application listener is allowed to call client.stop() again, so
|
|
193
|
+
# no component method may run under the lifecycle lock.
|
|
194
|
+
log.info("FB Python SDK: Python SDK client is closing...")
|
|
195
|
+
# Stop producers before consumers, and isolate every component so
|
|
196
|
+
# one extension failure cannot prevent the remaining resources
|
|
197
|
+
# from being released or escape into application shutdown code.
|
|
198
|
+
for name, component in (
|
|
199
|
+
('update processor', self._update_processor),
|
|
200
|
+
('event processor', self._event_processor),
|
|
201
|
+
('notice broadcaster', self._broadcaster),
|
|
202
|
+
('data storage', self._data_storage)):
|
|
203
|
+
try:
|
|
204
|
+
component.stop()
|
|
205
|
+
except Exception:
|
|
206
|
+
log.exception('FB Python SDK: %s failed to stop' % name)
|
|
207
|
+
finally:
|
|
208
|
+
with self._stop_lock:
|
|
209
|
+
self._stop_owner = None
|
|
210
|
+
self._stop_complete.set()
|
|
162
211
|
|
|
163
212
|
def __enter__(self):
|
|
164
213
|
return self
|
|
@@ -174,17 +223,21 @@ class FBClient:
|
|
|
174
223
|
def _get_flag_internal(self, key: str) -> Optional[dict]:
|
|
175
224
|
return self._data_storage.get(FEATURE_FLAGS, key)
|
|
176
225
|
|
|
177
|
-
def __handle_default_value(self, key: str, default: Any) -> Tuple[Optional[str],
|
|
226
|
+
def __handle_default_value(self, key: str, default: Any) -> Tuple[Optional[str], Any]:
|
|
178
227
|
default_value = self._config.get_default_value(key, default)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
228
|
+
try:
|
|
229
|
+
default_value_type = simple_type_inference(default_value)
|
|
230
|
+
if default_value is None:
|
|
231
|
+
return None, None
|
|
232
|
+
elif default_value_type == 'boolean':
|
|
233
|
+
return default_value_type, str(default_value).lower()
|
|
234
|
+
elif default_value_type == 'json':
|
|
235
|
+
return default_value_type, json.dumps(default_value)
|
|
236
|
+
else:
|
|
237
|
+
return default_value_type, str(default_value)
|
|
238
|
+
except Exception:
|
|
239
|
+
log.warning('FB Python SDK: unsupported default value; returning it unchanged on evaluation failure')
|
|
240
|
+
return None, default_value
|
|
188
241
|
|
|
189
242
|
def _evaluate_internal(self, key: str, user: dict, default: Any = None) -> _EvalResult:
|
|
190
243
|
default_value_type, default_value = self.__handle_default_value(key, default)
|
|
@@ -235,7 +288,7 @@ class FBClient:
|
|
|
235
288
|
:param default: the default value of the flag, to be used if the return value is not available
|
|
236
289
|
:return: one of the flag's values in any type in any type of string, bool, float, json
|
|
237
290
|
or the default value if flag evaluation fails
|
|
238
|
-
|
|
291
|
+
Unsupported defaults are returned unchanged if evaluation cannot produce a flag value.
|
|
239
292
|
"""
|
|
240
293
|
er = self._evaluate_internal(key, user, default)
|
|
241
294
|
return cast_variation_by_flag_type(er.flag_type, er.value)
|
|
@@ -252,7 +305,7 @@ class FBClient:
|
|
|
252
305
|
:param user: the attributes of the user
|
|
253
306
|
:param default: the default value of the flag, to be used if the return value is not available
|
|
254
307
|
:return: an :class:`fbclient.common_types.EvalDetail` object
|
|
255
|
-
|
|
308
|
+
Unsupported defaults are returned unchanged if evaluation cannot produce a flag value.
|
|
256
309
|
"""
|
|
257
310
|
return self._evaluate_internal(key, user, default).to_evail_detail
|
|
258
311
|
|
|
@@ -318,7 +371,11 @@ class FBClient:
|
|
|
318
371
|
schedules the next event delivery to be as soon as possible; however, the delivery still
|
|
319
372
|
happens asynchronously on a thread, so this method will return immediately.
|
|
320
373
|
"""
|
|
321
|
-
|
|
374
|
+
try:
|
|
375
|
+
if not self._closed:
|
|
376
|
+
self._event_processor.flush()
|
|
377
|
+
except Exception:
|
|
378
|
+
log.exception('FB Python SDK: event processor flush failed')
|
|
322
379
|
|
|
323
380
|
def identify(self, user: dict):
|
|
324
381
|
"""register an end user in the feature flag center
|
|
@@ -352,7 +409,6 @@ class FBClient:
|
|
|
352
409
|
log.warning('FB Python SDK: user invalid')
|
|
353
410
|
return
|
|
354
411
|
|
|
355
|
-
fb_user = FBUser.from_dict(user)
|
|
356
412
|
metric_event = MetricEvent(fb_user).add(Metric(event_name, metric_value))
|
|
357
413
|
self._event_handler(metric_event)
|
|
358
414
|
|
|
@@ -385,10 +441,15 @@ class FBClient:
|
|
|
385
441
|
:param json_str: feature flags, segments...etc in the json format
|
|
386
442
|
:return: True if the initialization is well done
|
|
387
443
|
"""
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
444
|
+
try:
|
|
445
|
+
if self._config.is_offline:
|
|
446
|
+
all_data = json.loads(json_str)
|
|
447
|
+
if valide_all_data(all_data):
|
|
448
|
+
version, data = _data_to_dict(all_data['data'])
|
|
449
|
+
if self._update_status_provider.init(data, version):
|
|
450
|
+
self._update_status_provider.update_state(State.ok_state())
|
|
451
|
+
return True
|
|
452
|
+
except Exception:
|
|
453
|
+
log.exception('FB Python SDK: invalid external bootstrap data')
|
|
393
454
|
|
|
394
455
|
return False
|
|
@@ -90,19 +90,21 @@ class EvalDetail(Jsonfy):
|
|
|
90
90
|
reason: str,
|
|
91
91
|
variation: Any,
|
|
92
92
|
key_name: Optional[str] = None,
|
|
93
|
-
name: Optional[str] = None
|
|
93
|
+
name: Optional[str] = None,
|
|
94
|
+
variation_id: Optional[str] = None):
|
|
94
95
|
"""Constructs an instance.
|
|
95
96
|
|
|
96
|
-
:param id: variation id
|
|
97
97
|
:param reason: main factor that influenced the flag evaluation value
|
|
98
98
|
:param variation: result of the flag evaluation in any type of string, bool, float/int, json(Python object) or default value if flag evaluation fails
|
|
99
99
|
:param key_name: key name of the flag
|
|
100
100
|
:param name: name of the flag
|
|
101
|
+
:param variation_id: stable identifier of the resolved variation, or None if evaluation failed
|
|
101
102
|
"""
|
|
102
103
|
self._reason = reason
|
|
103
104
|
self._variation = variation
|
|
104
105
|
self._key_name = key_name
|
|
105
106
|
self._name = name
|
|
107
|
+
self._variation_id = variation_id
|
|
106
108
|
|
|
107
109
|
@property
|
|
108
110
|
def reason(self) -> str:
|
|
@@ -129,6 +131,12 @@ class EvalDetail(Jsonfy):
|
|
|
129
131
|
"""
|
|
130
132
|
return self._name
|
|
131
133
|
|
|
134
|
+
@property
|
|
135
|
+
def variation_id(self) -> Optional[str]:
|
|
136
|
+
"""The stable identifier of the resolved variation, if evaluation succeeded.
|
|
137
|
+
"""
|
|
138
|
+
return self._variation_id
|
|
139
|
+
|
|
132
140
|
def to_json_dict(self) -> dict:
|
|
133
141
|
json_dict = {}
|
|
134
142
|
json_dict['reason'] = self.reason
|
|
@@ -329,7 +337,8 @@ class _EvalResult:
|
|
|
329
337
|
@property
|
|
330
338
|
def to_evail_detail(self) -> "EvalDetail":
|
|
331
339
|
_value = cast_variation_by_flag_type(self.__flag_type, self.__value)
|
|
332
|
-
|
|
340
|
+
variation_id = self.__id if self.is_success else None
|
|
341
|
+
return EvalDetail(self.__reason, _value, self.__key_name, self.__name, variation_id)
|
|
333
342
|
|
|
334
343
|
@property
|
|
335
344
|
def to_flag_state(self) -> "FlagState":
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from copy import deepcopy
|
|
1
2
|
from threading import Event
|
|
2
3
|
from typing import Any, Callable, Dict, Optional, Tuple
|
|
3
4
|
|
|
@@ -135,8 +136,8 @@ class Config:
|
|
|
135
136
|
data_storage: Optional[DataStorage] = None,
|
|
136
137
|
update_processor_imp: Optional[Callable[['Config', DataUpdateStatusProvider, Event], UpdateProcessor]] = None,
|
|
137
138
|
event_processor_imp: Optional[Callable[['Config', Sender], EventProcessor]] = None,
|
|
138
|
-
http: HTTPConfig =
|
|
139
|
-
websocket: WebSocketConfig =
|
|
139
|
+
http: Optional[HTTPConfig] = None,
|
|
140
|
+
websocket: Optional[WebSocketConfig] = None,
|
|
140
141
|
defaults: Optional[dict] = None):
|
|
141
142
|
|
|
142
143
|
self.__env_secret = env_secret
|
|
@@ -145,21 +146,24 @@ class Config:
|
|
|
145
146
|
self.__streaming_first_retry_delay = 1.0 if streaming_first_retry_delay is None or streaming_first_retry_delay <= 0 else min(
|
|
146
147
|
streaming_first_retry_delay, 60.0)
|
|
147
148
|
self.__offline = offline
|
|
148
|
-
self.__data_storage = data_storage if data_storage else InMemoryDataStorage()
|
|
149
|
+
self.__data_storage = data_storage if data_storage is not None else InMemoryDataStorage()
|
|
149
150
|
self.__event_processor_imp = event_processor_imp
|
|
150
151
|
self.__update_processor_imp = update_processor_imp
|
|
151
|
-
self.__events_max_in_queue = 10000 if events_max_in_queue is None else
|
|
152
|
+
self.__events_max_in_queue = 10000 if events_max_in_queue is None or events_max_in_queue <= 0 else events_max_in_queue
|
|
152
153
|
self.__events_flush_interval = 1.0 if events_flush_interval is None or events_flush_interval <= 0 else min(
|
|
153
154
|
events_flush_interval, 3.0)
|
|
154
155
|
self.__events_retry_interval = 0.1 if events_retry_interval is None or events_retry_interval <= 0 else min(
|
|
155
156
|
events_retry_interval, 1)
|
|
156
157
|
self.__events_max_retries = 1 if events_max_retries is None or events_max_retries <= 0 else min(
|
|
157
158
|
events_max_retries, 3)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
self.
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
# Avoid sharing mutable default configuration objects between SDK
|
|
160
|
+
# clients created by unrelated applications or tests.
|
|
161
|
+
self.__http = http if http is not None else HTTPConfig()
|
|
162
|
+
self.__websocket = websocket if websocket is not None else WebSocketConfig()
|
|
163
|
+
self.__defaults = deepcopy(defaults) if defaults is not None else {}
|
|
164
|
+
|
|
165
|
+
def copy_config_in_a_new_env(self, env_secret: str, defaults=None,
|
|
166
|
+
data_storage: Optional[DataStorage] = None) -> 'Config':
|
|
163
167
|
return Config(env_secret,
|
|
164
168
|
event_url=self.__event_url,
|
|
165
169
|
streaming_url=self.__streaming_url,
|
|
@@ -169,14 +173,17 @@ class Config:
|
|
|
169
173
|
events_retry_interval=self.__events_retry_interval,
|
|
170
174
|
events_max_retries=self.__events_max_retries,
|
|
171
175
|
offline=self.__offline,
|
|
172
|
-
|
|
176
|
+
# Environment data must never leak between clients. A
|
|
177
|
+
# caller that intentionally wants a custom store can
|
|
178
|
+
# still provide one explicitly.
|
|
179
|
+
data_storage=data_storage,
|
|
173
180
|
update_processor_imp=self.__update_processor_imp,
|
|
174
181
|
event_processor_imp=self.__event_processor_imp,
|
|
175
|
-
http=self.__http,
|
|
176
|
-
websocket=self.__websocket,
|
|
182
|
+
http=deepcopy(self.__http),
|
|
183
|
+
websocket=deepcopy(self.__websocket),
|
|
177
184
|
defaults=defaults if defaults is not None else self.__defaults)
|
|
178
185
|
|
|
179
|
-
def get_default_value(self, key, default=None) ->
|
|
186
|
+
def get_default_value(self, key, default=None) -> Any:
|
|
180
187
|
return self.__defaults.get(key, default)
|
|
181
188
|
|
|
182
189
|
@property
|