Skip to content

Commit c497ab7

Browse files
mrm9084rossgrambo
andauthored
GA Release (#29)
* GA Prep * Update CHANGELOG.md * Update README.md Co-authored-by: Ross Grambo <rossgrambo@microsoft.com> --------- Co-authored-by: Ross Grambo <rossgrambo@microsoft.com>
1 parent a26f230 commit c497ab7

3 files changed

Lines changed: 15 additions & 266 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
## 1.0.0 (06/26/2024)
4+
5+
Updated version to 1.0.0.
6+
37
## 1.0.0b1 (05/22/2024)
48

59
New Feature Management library.

README.md

Lines changed: 10 additions & 265 deletions
Original file line numberDiff line numberDiff line change
@@ -1,274 +1,21 @@
11
# Microsoft Feature Management for Python
22

3-
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.
3+
[![FeatureManagement](https://img.shields.io/pypi/v/FeatureManagement?label=FeatureManagement)](https://pypi.org/project/FeatureManagement/)
44

5-
## Getting started
5+
Feature management provides a way to develop and expose application functionality based on features. Many applications have special requirements when a new feature is developed such as when the feature should be enabled and under what conditions. This library provides a way to define these relationships, and also integrates into common Python code patterns to make exposing these features possible.
66

7-
### Prerequisites
7+
## Get Started
88

9-
* Python 3.7 or later is required to use this package.
9+
[Quickstart](https://learn.microsoft.com/azure/azure-app-configuration/quickstart-feature-flag-python): A quickstart guide is available to learn how to integrate feature flags from Azure App Configuration into your Python applications.
1010

11-
### Install the package
11+
[API Reference](https://microsoft.github.io/FeatureManagement-Python/): This API reference details the API surface of the libraries contained within this repository.
1212

13-
Install the Python feature management client library for Python with [pip][pip]:
13+
## Examples
1414

15-
```bash
16-
pip install featuremanagement
17-
```
18-
19-
## Usage
20-
21-
You can use feature flags from the Azure App Configuration service, a json file, or a dictionary.
22-
23-
### Use feature flags from Azure App Configuration
24-
25-
```python
26-
from featuremanagement import FeatureManager
27-
from azure.appconfiguration.provider import load
28-
from azure.identity import DefaultAzureCredential
29-
import os
30-
31-
endpoint = os.environ.get("APPCONFIGURATION_ENDPOINT_STRING")
32-
33-
# If no setting selector is set then feature flags with no label are loaded.
34-
selects = {SettingSelector(key_filter=".appconfig.featureflag*")}
35-
36-
config = load(endpoint=endpoint, credential=DefaultAzureCredential(), selects=selects)
37-
38-
feature_manager = FeatureManager(config)
39-
40-
# Prints the value of the feature flag Alpha
41-
print("Alpha is ", feature_manager.is_enabled("Alpha"))
42-
```
43-
44-
### Use feature flags from a json file
45-
46-
A Json file with the following format can be used to load feature flags.
47-
48-
```json
49-
{
50-
"feature_management": {
51-
"feature_flags": [
52-
{
53-
"id": "Alpha",
54-
"description": "",
55-
"enabled": "true",
56-
"conditions": {
57-
"client_filters": []
58-
}
59-
}
60-
]
61-
}
62-
}
63-
```
64-
65-
Load feature flags from a json file.
66-
67-
```python
68-
from featuremanagement import FeatureManager
69-
import json
70-
import os
71-
import sys
72-
73-
script_directory = os.path.dirname(os.path.abspath(sys.argv[0]))
74-
75-
f = open(script_directory + "/my_json_file.json", "r")
76-
77-
feature_flags = json.load(f)
78-
79-
feature_manager = FeatureManager(feature_flags)
80-
81-
# Returns the value of Alpha, based on the result of the feature filter
82-
print("Alpha is ", feature_manager.is_enabled("Alpha"))
83-
```
84-
85-
### Use feature flags from a dictionary
86-
87-
```python
88-
from featuremanagement import FeatureManager
89-
90-
feature_flags = {
91-
"feature_management": {
92-
"feature_flags": [
93-
{
94-
"id": "Alpha",
95-
"description": "",
96-
"enabled": "true",
97-
"conditions": {
98-
"client_filters": []
99-
}
100-
}
101-
]
102-
}
103-
}
104-
105-
feature_manager = FeatureManager(feature_flags)
106-
107-
# Is always true
108-
print("Alpha is ", feature_manager.is_enabled("Alpha"))
109-
```
110-
111-
## Key concepts
112-
113-
### FeatureManager
114-
115-
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.
116-
117-
### Feature Flags
118-
119-
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.
120-
121-
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).
122-
123-
```javascript
124-
{
125-
"id": "Alpha",
126-
"enabled": "true",
127-
"conditions": {
128-
"client_filters": [
129-
{
130-
"name": "MyFilter",
131-
"parameters": {
132-
...
133-
}
134-
}
135-
]
136-
}
137-
}
138-
```
139-
140-
This object is passed into the `FeatureManager` when it is initialized.
141-
142-
### Feature Filters
143-
144-
Feature filters enable dynamic evaluation of feature flags. The Python feature management library includes two built-in filters:
145-
146-
- `Microsoft.TimeWindow` - Enables a feature flag based on a time window.
147-
- `Microsoft.Targeting` - Enables a feature flag based on a list of users, groups, or rollout percentages.
148-
149-
#### Time Window Filter
150-
151-
The Time Window Filter enables a feature flag based on a time window. It has two parameters:
152-
153-
- `Start` - The start time of the time window.
154-
- `End` - The end time of the time window.
155-
156-
```json
157-
{
158-
"name": "Microsoft.TimeWindow",
159-
"parameters": {
160-
"Start": "2020-01-01T00:00:00Z",
161-
"End": "2020-12-31T00:00:00Z"
162-
}
163-
}
164-
```
165-
166-
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.
167-
168-
#### Targeting Filter
169-
170-
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.
171-
172-
The following steps demonstrate an example of a progressive rollout for a new 'Beta' feature:
173-
174-
1. Individual users Jeff and Alicia are granted access to the Beta
175-
1. Another user, Mark, asks to opt-in and is included.
176-
1. Twenty percent of a group known as "Ring1" users are included in the Beta.
177-
1. The number of "Ring1" users included in the beta is bumped up to 100 percent.
178-
1. Five percent of the user base is included in the beta.
179-
1. The rollout percentage is bumped up to 100 percent and the feature is completely rolled out.
180-
181-
This strategy for rolling out a feature is built in to the library through the included Microsoft.Targeting feature filter.
182-
183-
##### Defining a Targeting Feature Filter
184-
185-
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:
186-
187-
- `Users` - A list of users that the feature flag is enabled for.
188-
- `Groups` - A list of groups that the feature flag is enabled for and a rollout percentage for each group.
189-
- `Name` - The name of the group.
190-
- `RolloutPercentage` - A percentage value that the feature flag is enabled for in the given group.
191-
- `DefaultRolloutPercentage` - A percentage value that the feature flag is enabled for.
192-
- `Exclusion` - An object that contains a list of users and groups that the feature flag is disabled for.
193-
- `Users` - A list of users that the feature flag is disabled for.
194-
- `Groups` - A list of groups that the feature flag is disabled for.
195-
196-
```json
197-
{
198-
"name": "Microsoft.Targeting",
199-
"parameters": {
200-
"Audience": {
201-
"Users": ["user1", "user2"],
202-
"Groups": [
203-
{
204-
"Name": "group1",
205-
"RolloutPercentage": 100
206-
}
207-
],
208-
"DefaultRolloutPercentage": 50,
209-
"Exclusion": {
210-
"Users": ["user3"],
211-
"Groups": ["group2"]
212-
}
213-
}
214-
}
215-
}
216-
```
217-
218-
##### Using Targeting Feature Filter
219-
220-
You can provide the current user info through `kwargs` when calling `isEnabled`.
221-
222-
```python
223-
from featuremanagement import FeatureManager, TargetingContext
224-
225-
# Returns true, because user1 is in the Users list
226-
feature_manager.is_enabled("Beta", TargetingContext(user_id="user1", groups=["group1"]))
227-
228-
# Returns false, because group2 is in the Exclusion.Groups list
229-
feature_manager.is_enabled("Beta", TargetingContext(user_id="user1", groups=["group2"]))
230-
231-
# Has a 50% chance of returning true, but will be conisistent for the same user
232-
feature_manager.is_enabled("Beta", TargetingContext(user_id="user4"))
233-
```
234-
235-
#### Custom Filters
236-
237-
You can also create your own feature filters by implementing the `FeatureFilter` interface.
238-
239-
```python
240-
class MyCustomFilter(FeatureFilter):
241-
242-
def evaluate(self, context, **kwargs):
243-
...
244-
return True
245-
```
246-
247-
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.
248-
249-
```python
250-
251-
feature_manager = FeatureManager(feature_flags, feature_filters={MyCustomFilter(), MyOtherFilter()})
252-
```
253-
254-
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`.
255-
256-
```javascript
257-
{
258-
"name": "CustomFilter",
259-
"parameters": {
260-
...
261-
}
262-
}
263-
```
264-
265-
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.
266-
267-
```python
268-
@FeatureFilter.alias("AliasFilter")
269-
class MyCustomFilter(FeatureFilter):
270-
...
271-
```
15+
* [Python Application](https://github.com/microsoft/FeatureManagement-Python/blob/main/samples/feature_flag_sample.py)
16+
* [Python Application with Azure App Configuration](https://github.com/microsoft/FeatureManagement-Python/blob/main/samples/feature_flag_with_azure_app_configuration_sample.py)
17+
* [Django Application](https://github.com/Azure/AppConfiguration/tree/main/examples/Python/python-django-webapp-sample)
18+
* [Flask Application](https://github.com/Azure/AppConfiguration/tree/main/examples/Python/python-flask-webapp-sample)
27219

27320
## Contributing
27421

@@ -291,5 +38,3 @@ trademarks or logos is subject to and must follow
29138
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
29239
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
29340
Any use of third-party trademarks or logos are subject to those third-party's policies.
294-
295-
[pip]: https://pypi.org/project/FeatureManagement/

featuremanagement/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# license information.
55
# -------------------------------------------------------------------------
66

7-
VERSION = "1.0.0b1"
7+
VERSION = "1.0.0"

0 commit comments

Comments
 (0)