Skip to content

Commit 800bf77

Browse files
authored
chore: v6 migration guide (#328)
1 parent fa88e22 commit 800bf77

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
This is the Python client for [Unleash](https://github.com/unleash/unleash). It implements [Client Specifications 1.0](https://docs.getunleash.io/client-specification) and checks compliance based on spec in [unleash/client-specifications](https://github.com/Unleash/client-specification)
77

8+
> **Migrating to v6**
9+
>
10+
> If you use custom strategies or access the `features` property on the Unleash Client, read the complete [migration guide](./v6_MIGRATION_GUIDE.md) before upgrading to v6.
11+
12+
813
What it supports:
914
* Default activation strategies using 32-bit [Murmurhash3](https://en.wikipedia.org/wiki/MurmurHash)
1015
* Custom strategies

v6_MIGRATION_GUIDE.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Migrating to Unleash-Client-Python 6.0.0
2+
3+
This guide highlights the key changes you should be aware of when upgrading to v6.0.0 of the Unleash client.
4+
5+
## Removed direct access to feature flags
6+
7+
Direct access to the feature flag objects through `UnleashClient.features` has been removed. All classes related to the internal representation of feature flags are no longer publicly accessible in the SDK.
8+
9+
The SDK now provides an `UnleashClient.feature_definitions()` method, which returns a list of feature flag names, their type, and the project they're bound to.
10+
11+
## Changes to custom strategies
12+
13+
Custom strategies have undergone some changes that require updates to their implementations. This is a strict requirement: any strategy that does not implement the correct interface will throw an exception at startup.
14+
15+
The interface changes are as follows:
16+
17+
- Strategies no longer inherit from a base class.
18+
- The apply method now accepts a second parameter, `parameters`. In legacy versions, this functionality was managed by the `load_provisioning()` method.
19+
20+
Here is an example of a legacy strategy:
21+
22+
``` python
23+
class CatStrategy(Strategy):
24+
def load_provisioning(self) -> list:
25+
return [x.strip() for x in self.parameters["sound"].split(",")]
26+
27+
def apply(self, context: dict = None) -> bool:
28+
default_value = False
29+
30+
if "sound" in context.keys():
31+
default_value = context["sound"] in self.parsed_provisioning
32+
33+
return default_value
34+
```
35+
36+
This is now written as:
37+
38+
``` python
39+
class CatStrategy:
40+
def apply(self, parameters: dict, context: dict = None) -> bool:
41+
default_value = False
42+
43+
parsed_parameters = [x.strip() for x in parameters["sound"].split(",")]
44+
45+
if "sound" in context.keys():
46+
default_value = context["sound"] in parsed_parameters
47+
48+
return default_value
49+
50+
```
51+
52+
Strategies are now mounted as an instance rather than a class object when configuring the SDK:
53+
54+
``` python
55+
56+
custom_strategies_dict = {"amIACat": CatStrategy()}
57+
58+
unleash_client = UnleashClient(
59+
"some_unleash_url", "some_app_name", custom_strategies=custom_strategies_dict
60+
)
61+
62+
```

0 commit comments

Comments
 (0)