|
| 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