⌨ Quickstart TL;DR¶
Keeping someone from using your unfinished feature¶
In [1]:
Copied!
from fastfeatureflag.feature_flag import feature_flag
from fastfeatureflag.feature_flag import feature_flag
In [2]:
Copied!
def not_finished_feature():
return "Not finished"
not_finished_feature()
def not_finished_feature():
return "Not finished"
not_finished_feature()
Out[2]:
'Not finished'
In [3]:
Copied!
@feature_flag() # == @feature_flag("off")
def not_finished_feature():
return "Not finished"
not_finished_feature()
@feature_flag() # == @feature_flag("off")
def not_finished_feature():
return "Not finished"
not_finished_feature()
--------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) Cell In[3], line 5 1 @feature_flag() # == @feature_flag("off") 2 def not_finished_feature(): 3 return "Not finished" ----> 5 not_finished_feature() File /opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/fastfeatureflag/feature_flag_configuration.py:62, in FeatureFlagConfiguration.__call__(self, *args, **kwargs) 59 if self.feature.shadow: 60 return self._shadow_function(*args, **kwargs) ---> 62 return self._decorated_function(*args, **kwargs) File /opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/fastfeatureflag/feature_flag_configuration.py:202, in FeatureFlagConfiguration._decorated_function(self, *args, **kwargs) 199 if self.feature.response: 200 return self.feature.response --> 202 raise NotImplementedError("Feature not implemented") from None 204 if ( 205 self.feature.activation == "on" 206 or os.environ.get(self.feature.activation) == "on" 207 ): 208 self._options = self._options | kwargs NotImplementedError: Feature not implemented
activate the feature
In [4]:
Copied!
@feature_flag("on")
def not_finished_feature():
return "Not finished"
not_finished_feature()
@feature_flag("on")
def not_finished_feature():
return "Not finished"
not_finished_feature()
Out[4]:
'Not finished'
Response differently if feature is deactivated¶
In [5]:
Copied!
@feature_flag("off", response="Go on")
def not_finished_feature():
return "Not finished"
not_finished_feature()
@feature_flag("off", response="Go on")
def not_finished_feature():
return "Not finished"
not_finished_feature()
Out[5]:
'Go on'
In [6]:
Copied!
def mocked_data():
return {"mocked":"data"}
@feature_flag("off", response=mocked_data())
def not_finished_feature():
return "Not finished"
not_finished_feature()
def mocked_data():
return {"mocked":"data"}
@feature_flag("off", response=mocked_data())
def not_finished_feature():
return "Not finished"
not_finished_feature()
Out[6]:
{'mocked': 'data'}
Group features by naming them¶
In [7]:
Copied!
@feature_flag("off", name="grouped_features")
def not_finished_feature_one():
return "Not finished feature one"
@feature_flag()
def not_finished_feature_two(name="grouped_features"):
return "Not finished feature two"
@feature_flag("off", name="grouped_features")
def not_finished_feature_one():
return "Not finished feature one"
@feature_flag()
def not_finished_feature_two(name="grouped_features"):
return "Not finished feature two"
In [8]:
Copied!
not_finished_feature_one()
not_finished_feature_one()
--------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) Cell In[8], line 1 ----> 1 not_finished_feature_one() File /opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/fastfeatureflag/feature_flag_configuration.py:62, in FeatureFlagConfiguration.__call__(self, *args, **kwargs) 59 if self.feature.shadow: 60 return self._shadow_function(*args, **kwargs) ---> 62 return self._decorated_function(*args, **kwargs) File /opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/fastfeatureflag/feature_flag_configuration.py:202, in FeatureFlagConfiguration._decorated_function(self, *args, **kwargs) 199 if self.feature.response: 200 return self.feature.response --> 202 raise NotImplementedError("Feature not implemented") from None 204 if ( 205 self.feature.activation == "on" 206 or os.environ.get(self.feature.activation) == "on" 207 ): 208 self._options = self._options | kwargs NotImplementedError: Feature not implemented
In [9]:
Copied!
not_finished_feature_two()
not_finished_feature_two()
--------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) Cell In[9], line 1 ----> 1 not_finished_feature_two() File /opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/fastfeatureflag/feature_flag_configuration.py:62, in FeatureFlagConfiguration.__call__(self, *args, **kwargs) 59 if self.feature.shadow: 60 return self._shadow_function(*args, **kwargs) ---> 62 return self._decorated_function(*args, **kwargs) File /opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/fastfeatureflag/feature_flag_configuration.py:202, in FeatureFlagConfiguration._decorated_function(self, *args, **kwargs) 199 if self.feature.response: 200 return self.feature.response --> 202 raise NotImplementedError("Feature not implemented") from None 204 if ( 205 self.feature.activation == "on" 206 or os.environ.get(self.feature.activation) == "on" 207 ): 208 self._options = self._options | kwargs NotImplementedError: Feature not implemented
we want to reuse the feature name, therefore we have to clean all registered features
In [10]:
Copied!
not_finished_feature_one.clean()
not_finished_feature_one.clean()
changing the activation of the first appearing feature_flag
activates both features
In [11]:
Copied!
@feature_flag("on", name="grouped_features")
def not_finished_feature_one():
return "Not finished feature one"
@feature_flag(name="grouped_features")
def not_finished_feature_two():
return "Not finished feature two"
@feature_flag("on", name="grouped_features")
def not_finished_feature_one():
return "Not finished feature one"
@feature_flag(name="grouped_features")
def not_finished_feature_two():
return "Not finished feature two"
In [12]:
Copied!
not_finished_feature_one()
not_finished_feature_one()
Out[12]:
'Not finished feature one'
In [13]:
Copied!
not_finished_feature_two()
not_finished_feature_two()
Out[13]:
'Not finished feature two'
Last update:
October 28, 2023
Created: October 28, 2023
Created: October 28, 2023