FeatureManagement 1.0.0b1__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 (43) hide show
  1. featuremanagement-1.0.0b1/CHANGELOG.md +13 -0
  2. featuremanagement-1.0.0b1/CODE_OF_CONDUCT.md +9 -0
  3. featuremanagement-1.0.0b1/FeatureManagement.egg-info/PKG-INFO +340 -0
  4. featuremanagement-1.0.0b1/FeatureManagement.egg-info/SOURCES.txt +41 -0
  5. featuremanagement-1.0.0b1/FeatureManagement.egg-info/dependency_links.txt +1 -0
  6. featuremanagement-1.0.0b1/FeatureManagement.egg-info/not-zip-safe +1 -0
  7. featuremanagement-1.0.0b1/FeatureManagement.egg-info/requires.txt +4 -0
  8. featuremanagement-1.0.0b1/FeatureManagement.egg-info/top_level.txt +1 -0
  9. featuremanagement-1.0.0b1/LICENSE +21 -0
  10. featuremanagement-1.0.0b1/MANIFEST.in +6 -0
  11. featuremanagement-1.0.0b1/PKG-INFO +340 -0
  12. featuremanagement-1.0.0b1/README.md +293 -0
  13. featuremanagement-1.0.0b1/SECURITY.md +41 -0
  14. featuremanagement-1.0.0b1/SUPPORT.md +25 -0
  15. featuremanagement-1.0.0b1/featuremanagement/__init__.py +20 -0
  16. featuremanagement-1.0.0b1/featuremanagement/_defaultfilters.py +162 -0
  17. featuremanagement-1.0.0b1/featuremanagement/_featurefilters.py +48 -0
  18. featuremanagement-1.0.0b1/featuremanagement/_featuremanager.py +190 -0
  19. featuremanagement-1.0.0b1/featuremanagement/_models/__init__.py +12 -0
  20. featuremanagement-1.0.0b1/featuremanagement/_models/_constants.py +18 -0
  21. featuremanagement-1.0.0b1/featuremanagement/_models/_evaluation_event.py +23 -0
  22. featuremanagement-1.0.0b1/featuremanagement/_models/_feature_conditions.py +70 -0
  23. featuremanagement-1.0.0b1/featuremanagement/_models/_feature_flag.py +102 -0
  24. featuremanagement-1.0.0b1/featuremanagement/_models/_targeting_context.py +27 -0
  25. featuremanagement-1.0.0b1/featuremanagement/_version.py +7 -0
  26. featuremanagement-1.0.0b1/featuremanagement/aio/__init__.py +10 -0
  27. featuremanagement-1.0.0b1/featuremanagement/aio/_defaultfilters.py +51 -0
  28. featuremanagement-1.0.0b1/featuremanagement/aio/_featurefilters.py +48 -0
  29. featuremanagement-1.0.0b1/featuremanagement/aio/_featuremanager.py +142 -0
  30. featuremanagement-1.0.0b1/featuremanagement/py.typed +0 -0
  31. featuremanagement-1.0.0b1/pyproject.toml +47 -0
  32. featuremanagement-1.0.0b1/samples/feature_flag_sample.py +34 -0
  33. featuremanagement-1.0.0b1/samples/feature_flag_with_azure_app_configuration_sample.py +46 -0
  34. featuremanagement-1.0.0b1/samples/formatted_feature_flags.json +230 -0
  35. featuremanagement-1.0.0b1/samples/random_filter.py +21 -0
  36. featuremanagement-1.0.0b1/setup.cfg +4 -0
  37. featuremanagement-1.0.0b1/setup.py +64 -0
  38. featuremanagement-1.0.0b1/tests/test_default_feature_flags.py +263 -0
  39. featuremanagement-1.0.0b1/tests/test_default_feature_flags_async.py +268 -0
  40. featuremanagement-1.0.0b1/tests/test_feature_manager.py +136 -0
  41. featuremanagement-1.0.0b1/tests/test_feature_manager_async.py +143 -0
  42. featuremanagement-1.0.0b1/tests/test_feature_manager_refresh.py +65 -0
  43. featuremanagement-1.0.0b1/tests/validation_tests/test_json_validations.py +101 -0
@@ -0,0 +1,13 @@
1
+ # Release History
2
+
3
+ ## 1.0.0b1 (05/22/2024)
4
+
5
+ New Feature Management library.
6
+
7
+ Provides the ability to manage feature flags in a project. Enables:
8
+
9
+ * Loading of feature flags from a file, see: https://github.com/Azure/AppConfiguration/blob/main/docs/FeatureManagement/FeatureManagement.v2.0.0.schema.json
10
+ * Loading of feature flags from Azure App Configuration.
11
+ * Checking if a feature is enabled.
12
+ * Default feature filters: TimeWindowFilter, TargetingFilter.
13
+ * Custom feature filters.
@@ -0,0 +1,9 @@
1
+ # Microsoft Open Source Code of Conduct
2
+
3
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4
+
5
+ Resources:
6
+
7
+ - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8
+ - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9
+ - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
@@ -0,0 +1,340 @@
1
+ Metadata-Version: 2.1
2
+ Name: FeatureManagement
3
+ Version: 1.0.0b1
4
+ Summary: A library for enabling/disabling features at runtime.
5
+ Home-page: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/appconfiguration/feature-management
6
+ Author: Microsoft Corporation
7
+ Author-email: Microsoft Corporation <appconfig@microsoft.com>
8
+ License: MIT License
9
+
10
+ Copyright (c) Microsoft Corporation.
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE
29
+
30
+ Project-URL: Homepage, https://github.com/microsoft/FeatureManagement-Python
31
+ Project-URL: Issues, https://github.com/microsoft/FeatureManagement-Python/issues
32
+ Classifier: Development Status :: 5 - Production/Stable
33
+ Classifier: Programming Language :: Python
34
+ Classifier: Programming Language :: Python :: 3 :: Only
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.8
37
+ Classifier: Programming Language :: Python :: 3.9
38
+ Classifier: Programming Language :: Python :: 3.10
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: License :: OSI Approved :: MIT License
41
+ Requires-Python: >=3.6
42
+ Description-Content-Type: text/markdown
43
+ License-File: LICENSE
44
+ Provides-Extra: appinsights
45
+ Requires-Dist: azure-monitor-opentelemetry<2.0.0,>=1.3.0; extra == "appinsights"
46
+ Requires-Dist: azure-monitor-events-extension<2.0.0; extra == "appinsights"
47
+
48
+ # Microsoft Feature Management for Python
49
+
50
+ Feature Management is a library for enabling/disabling features at runtime. Developers can use feature flags in simple use cases like conditional statement to more advanced scenarios like conditionally adding routes.
51
+
52
+ ## Getting started
53
+
54
+ ### Prerequisites
55
+
56
+ * Python 3.7 or later is required to use this package.
57
+
58
+ ### Install the package
59
+
60
+ Install the Python feature management client library for Python with [pip][pip]:
61
+
62
+ ```bash
63
+ pip install microsoft-featuremanagement
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ You can use feature flags from the Azure App Configuration service, a json file, or a dictionary.
69
+
70
+ ### Use feature flags from Azure App Configuration
71
+
72
+ ```python
73
+ from featuremanagement import FeatureManager
74
+ from azure.appconfiguration.provider import load
75
+ from azure.identity import DefaultAzureCredential
76
+ import os
77
+
78
+ endpoint = os.environ.get("APPCONFIGURATION_ENDPOINT_STRING")
79
+
80
+ # If no setting selector is set then feature flags with no label are loaded.
81
+ selects = {SettingSelector(key_filter=".appconfig.featureflag*")}
82
+
83
+ config = load(endpoint=endpoint, credential=DefaultAzureCredential(), selects=selects)
84
+
85
+ feature_manager = FeatureManager(config)
86
+
87
+ # Prints the value of the feature flag Alpha
88
+ print("Alpha is ", feature_manager.is_enabled("Alpha"))
89
+ ```
90
+
91
+ ### Use feature flags from a json file
92
+
93
+ A Json file with the following format can be used to load feature flags.
94
+
95
+ ```json
96
+ {
97
+ "feature_management": {
98
+ "feature_flags": [
99
+ {
100
+ "id": "Alpha",
101
+ "description": "",
102
+ "enabled": "true",
103
+ "conditions": {
104
+ "client_filters": []
105
+ }
106
+ }
107
+ ]
108
+ }
109
+ }
110
+ ```
111
+
112
+ Load feature flags from a json file.
113
+
114
+ ```python
115
+ from featuremanagement import FeatureManager
116
+ import json
117
+ import os
118
+ import sys
119
+
120
+ script_directory = os.path.dirname(os.path.abspath(sys.argv[0]))
121
+
122
+ f = open(script_directory + "/my_json_file.json", "r")
123
+
124
+ feature_flags = json.load(f)
125
+
126
+ feature_manager = FeatureManager(feature_flags)
127
+
128
+ # Returns the value of Alpha, based on the result of the feature filter
129
+ print("Alpha is ", feature_manager.is_enabled("Alpha"))
130
+ ```
131
+
132
+ ### Use feature flags from a dictionary
133
+
134
+ ```python
135
+ from featuremanagement import FeatureManager
136
+
137
+ feature_flags = {
138
+ "feature_management": {
139
+ "feature_flags": [
140
+ {
141
+ "id": "Alpha",
142
+ "description": "",
143
+ "enabled": "true",
144
+ "conditions": {
145
+ "client_filters": []
146
+ }
147
+ }
148
+ ]
149
+ }
150
+ }
151
+
152
+ feature_manager = FeatureManager(feature_flags)
153
+
154
+ # Is always true
155
+ print("Alpha is ", feature_manager.is_enabled("Alpha"))
156
+ ```
157
+
158
+ ## Key concepts
159
+
160
+ ### FeatureManager
161
+
162
+ The `FeatureManager` is the main entry point for using feature flags. It is initialized with a dictionary of feature flags, and optional feature filters. The `FeatureManager` can then be used to check if a feature is enabled or disabled.
163
+
164
+ ### Feature Flags
165
+
166
+ Feature Flags are objects that define how Feature Management enables/disables a feature. It contains an `id` and `enabled` property. The `id` is a string that uniquely identifies the feature flag. The `enabled` property is a boolean that indicates if the feature flag is enabled or disabled. The `conditions` object contains a property `client_filters` which is a list of `FeatureFilter` objects that are used to determine if the feature flag is enabled or disabled. The Feature Filters only run if the feature flag is enabled.
167
+
168
+ The full schema for a feature Flag can be found [here](https://github.com/Azure/AppConfiguration/blob/main/docs/FeatureManagement/FeatureFlag.v1.1.0.schema.json).
169
+
170
+ ```javascript
171
+ {
172
+ "id": "Alpha",
173
+ "enabled": "true",
174
+ "conditions": {
175
+ "client_filters": [
176
+ {
177
+ "name": "MyFilter",
178
+ "parameters": {
179
+ ...
180
+ }
181
+ }
182
+ ]
183
+ }
184
+ }
185
+ ```
186
+
187
+ This object is passed into the `FeatureManager` when it is initialized.
188
+
189
+ ### Feature Filters
190
+
191
+ Feature filters enable dynamic evaluation of feature flags. The Python feature management library includes two built-in filters:
192
+
193
+ - `Microsoft.TimeWindow` - Enables a feature flag based on a time window.
194
+ - `Microsoft.Targeting` - Enables a feature flag based on a list of users, groups, or rollout percentages.
195
+
196
+ #### Time Window Filter
197
+
198
+ The Time Window Filter enables a feature flag based on a time window. It has two parameters:
199
+
200
+ - `Start` - The start time of the time window.
201
+ - `End` - The end time of the time window.
202
+
203
+ ```json
204
+ {
205
+ "name": "Microsoft.TimeWindow",
206
+ "parameters": {
207
+ "Start": "2020-01-01T00:00:00Z",
208
+ "End": "2020-12-31T00:00:00Z"
209
+ }
210
+ }
211
+ ```
212
+
213
+ Both parameters are optional, but at least one is required. The time window filter is enabled after the start time and before the end time. If the start time is not specified, it is enabled immediately. If the end time is not specified, it will remain enabled after the start time.
214
+
215
+ #### Targeting Filter
216
+
217
+ Targeting is a feature management strategy that enables developers to progressively roll out new features to their user base. The strategy is built on the concept of targeting a set of users known as the target audience. An audience is made up of specific users, groups, excluded users/groups, and a designated percentage of the entire user base. The groups that are included in the audience can be broken down further into percentages of their total members.
218
+
219
+ The following steps demonstrate an example of a progressive rollout for a new 'Beta' feature:
220
+
221
+ 1. Individual users Jeff and Alicia are granted access to the Beta
222
+ 1. Another user, Mark, asks to opt-in and is included.
223
+ 1. Twenty percent of a group known as "Ring1" users are included in the Beta.
224
+ 1. The number of "Ring1" users included in the beta is bumped up to 100 percent.
225
+ 1. Five percent of the user base is included in the beta.
226
+ 1. The rollout percentage is bumped up to 100 percent and the feature is completely rolled out.
227
+
228
+ This strategy for rolling out a feature is built in to the library through the included Microsoft.Targeting feature filter.
229
+
230
+ ##### Defining a Targeting Feature Filter
231
+
232
+ The Targeting Filter provides the capability to enable a feature for a target audience. The filter parameters include an `Audience` object which describes users, groups, excluded users/groups, and a default percentage of the user base that should have access to the feature. The `Audience` object contains the following fields:
233
+
234
+ - `Users` - A list of users that the feature flag is enabled for.
235
+ - `Groups` - A list of groups that the feature flag is enabled for and a rollout percentage for each group.
236
+ - `Name` - The name of the group.
237
+ - `RolloutPercentage` - A percentage value that the feature flag is enabled for in the given group.
238
+ - `DefaultRolloutPercentage` - A percentage value that the feature flag is enabled for.
239
+ - `Exclusion` - An object that contains a list of users and groups that the feature flag is disabled for.
240
+ - `Users` - A list of users that the feature flag is disabled for.
241
+ - `Groups` - A list of groups that the feature flag is disabled for.
242
+
243
+ ```json
244
+ {
245
+ "name": "Microsoft.Targeting",
246
+ "parameters": {
247
+ "Audience": {
248
+ "Users": ["user1", "user2"],
249
+ "Groups": [
250
+ {
251
+ "Name": "group1",
252
+ "RolloutPercentage": 100
253
+ }
254
+ ],
255
+ "DefaultRolloutPercentage": 50,
256
+ "Exclusion": {
257
+ "Users": ["user3"],
258
+ "Groups": ["group2"]
259
+ }
260
+ }
261
+ }
262
+ }
263
+ ```
264
+
265
+ ##### Using Targeting Feature Filter
266
+
267
+ You can provide the current user info through `kwargs` when calling `isEnabled`.
268
+
269
+ ```python
270
+ from featuremanagement import FeatureManager, TargetingContext
271
+
272
+ # Returns true, because user1 is in the Users list
273
+ feature_manager.is_enabled("Beta", TargetingContext(user_id="user1", groups=["group1"]))
274
+
275
+ # Returns false, because group2 is in the Exclusion.Groups list
276
+ feature_manager.is_enabled("Beta", TargetingContext(user_id="user1", groups=["group2"]))
277
+
278
+ # Has a 50% chance of returning true, but will be conisistent for the same user
279
+ feature_manager.is_enabled("Beta", TargetingContext(user_id="user4"))
280
+ ```
281
+
282
+ #### Custom Filters
283
+
284
+ You can also create your own feature filters by implementing the `FeatureFilter` interface.
285
+
286
+ ```python
287
+ class MyCustomFilter(FeatureFilter):
288
+
289
+ def evaluate(self, context, **kwargs):
290
+ ...
291
+ return True
292
+ ```
293
+
294
+ They can then be passed into the `FeatureManager` when it is initialized. By default, the name of a feature filter is the name of the class. You can override this by setting a class attribute `alias` to the modified class name.
295
+
296
+ ```python
297
+
298
+ feature_manager = FeatureManager(feature_flags, feature_filters={MyCustomFilter(), MyOtherFilter()})
299
+ ```
300
+
301
+ The `evaluate` method is called when checking if a feature flag is enabled. The `context` parameter contains information about the feature filter from the `parameters` field of the feature filter. Any additional parameters can be passed in as keyword arguments when calling `is_enabled`.
302
+
303
+ ```javascript
304
+ {
305
+ "name": "CustomFilter",
306
+ "parameters": {
307
+ ...
308
+ }
309
+ }
310
+ ```
311
+
312
+ You can modify the name of a feature flag by using the `@FeatureFilter.alias` decorator. The alias overrides the name of the feature filter and needs to match the name of the feature filter in the feature flag json.
313
+
314
+ ```python
315
+ @FeatureFilter.alias("AliasFilter")
316
+ class MyCustomFilter(FeatureFilter):
317
+ ...
318
+ ```
319
+
320
+ ## Contributing
321
+
322
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
323
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
324
+ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
325
+
326
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
327
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
328
+ provided by the bot. You will only need to do this once across all repos using our CLA.
329
+
330
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
331
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
332
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
333
+
334
+ ## Trademarks
335
+
336
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
337
+ trademarks or logos is subject to and must follow
338
+ [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
339
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
340
+ Any use of third-party trademarks or logos are subject to those third-party's policies.
@@ -0,0 +1,41 @@
1
+ CHANGELOG.md
2
+ CODE_OF_CONDUCT.md
3
+ LICENSE
4
+ MANIFEST.in
5
+ README.md
6
+ SECURITY.md
7
+ SUPPORT.md
8
+ pyproject.toml
9
+ setup.py
10
+ FeatureManagement.egg-info/PKG-INFO
11
+ FeatureManagement.egg-info/SOURCES.txt
12
+ FeatureManagement.egg-info/dependency_links.txt
13
+ FeatureManagement.egg-info/not-zip-safe
14
+ FeatureManagement.egg-info/requires.txt
15
+ FeatureManagement.egg-info/top_level.txt
16
+ featuremanagement/__init__.py
17
+ featuremanagement/_defaultfilters.py
18
+ featuremanagement/_featurefilters.py
19
+ featuremanagement/_featuremanager.py
20
+ featuremanagement/_version.py
21
+ featuremanagement/py.typed
22
+ featuremanagement/_models/__init__.py
23
+ featuremanagement/_models/_constants.py
24
+ featuremanagement/_models/_evaluation_event.py
25
+ featuremanagement/_models/_feature_conditions.py
26
+ featuremanagement/_models/_feature_flag.py
27
+ featuremanagement/_models/_targeting_context.py
28
+ featuremanagement/aio/__init__.py
29
+ featuremanagement/aio/_defaultfilters.py
30
+ featuremanagement/aio/_featurefilters.py
31
+ featuremanagement/aio/_featuremanager.py
32
+ samples/feature_flag_sample.py
33
+ samples/feature_flag_with_azure_app_configuration_sample.py
34
+ samples/formatted_feature_flags.json
35
+ samples/random_filter.py
36
+ tests/test_default_feature_flags.py
37
+ tests/test_default_feature_flags_async.py
38
+ tests/test_feature_manager.py
39
+ tests/test_feature_manager_async.py
40
+ tests/test_feature_manager_refresh.py
41
+ tests/validation_tests/test_json_validations.py
@@ -0,0 +1,4 @@
1
+
2
+ [AppInsights]
3
+ azure-monitor-opentelemetry<2.0.0,>=1.3.0
4
+ azure-monitor-events-extension<2.0.0
@@ -0,0 +1 @@
1
+ featuremanagement
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
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 all
13
+ 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 THE
21
+ SOFTWARE
@@ -0,0 +1,6 @@
1
+ recursive-include tests *.py
2
+ include *.md
3
+ include LICENSE
4
+ include featuremanagement/*.py
5
+ include featuremanagement/aio/*.py
6
+ recursive-include samples *.py *.json