š³ feature_flag
Ā¶
The basic component of fastfeatureflag
.
UsageĀ¶
InĀ [1]:
Copied!
from fastfeatureflag.feature_flag import feature_flag
@feature_flag("off", name="grouped_feature", response="Custom response")
def broken_feature():
return "broken feature"
broken_feature()
from fastfeatureflag.feature_flag import feature_flag
@feature_flag("off", name="grouped_feature", response="Custom response")
def broken_feature():
return "broken feature"
broken_feature()
Out[1]:
'Custom response'
UpdateĀ¶
InĀ [2]:
Copied!
@feature_flag("off", name="grouped_feature", response="Custom response")
def broken_feature():
return "broken feature"
broken_feature()
@feature_flag("off", name="grouped_feature", response="Custom response")
def broken_feature():
return "broken feature"
broken_feature()
Out[2]:
'Custom response'
To change the behavior of the single feature_flag
, use the update method. Every flagged object has this function.
InĀ [3]:
Copied!
broken_feature.update(activation="on")
broken_feature()
broken_feature.update(activation="on")
broken_feature()
Out[3]:
'broken feature'
ConfigurationĀ¶
Having several features might make the update difficult. It is also possible to reconfigure all flags. Provided a configuration dictionary.
InĀ [4]:
Copied!
@feature_flag("off", name="grouped_feature", response="Custom response")
def broken_feature():
return "broken feature"
broken_feature()
@feature_flag("off", name="grouped_feature", response="Custom response")
def broken_feature():
return "broken feature"
broken_feature()
Out[4]:
'Custom response'
InĀ [5]:
Copied!
@feature_flag("off", name="grouped_feature", response="Custom response")
def broken_feature():
return "broken feature"
configuration = {"grouped_feature": {"activation":"on"}}
broken_feature.configuration = configuration
broken_feature()
@feature_flag("off", name="grouped_feature", response="Custom response")
def broken_feature():
return "broken feature"
configuration = {"grouped_feature": {"activation":"on"}}
broken_feature.configuration = configuration
broken_feature()
Out[5]:
'broken feature'
InĀ [6]:
Copied!
configuration = {"grouped_feature": {"activation":"off","response":"Configured response"}}
broken_feature.configuration = configuration
broken_feature()
configuration = {"grouped_feature": {"activation":"off","response":"Configured response"}}
broken_feature.configuration = configuration
broken_feature()
Out[6]:
'Configured response'
Reconfiguration via a fileĀ¶
Instead of providing a dictionary, it is also possible to point to a *.toml
file, containing the configuration.
InĀ [7]:
Copied!
with open("sample_config.toml","r") as file:
print(file.read())
with open("sample_config.toml","r") as file:
print(file.read())
[grouped_feature] activation="off" response="Response defined by toml"
InĀ [8]:
Copied!
@feature_flag("off", name="grouped_feature")
def broken_feature():
return "broken feature"
broken_feature()
@feature_flag("off", name="grouped_feature")
def broken_feature():
return "broken feature"
broken_feature()
Out[8]:
'Configured response'
InĀ [9]:
Copied!
import pathlib
broken_feature.configuration_path = pathlib.Path("sample_config.toml")
broken_feature()
import pathlib
broken_feature.configuration_path = pathlib.Path("sample_config.toml")
broken_feature()
Out[9]:
'Response defined by toml'
Show and clean registered featuresĀ¶
It might be necessary to clean all registered features (un-grouping the features).
InĀ [10]:
Copied!
@feature_flag("off", name="grouped_feature")
def broken_feature():
return "broken feature"
broken_feature.registered_features
@feature_flag("off", name="grouped_feature")
def broken_feature():
return "broken feature"
broken_feature.registered_features
Out[10]:
[FeatureContent(activation='off', name='grouped_feature', response='Response defined by toml', shadow=None, func=<function broken_feature at 0x7fe0c8d17c40>, configuration=None, configuration_path=None)]
InĀ [11]:
Copied!
broken_feature.clean()
broken_feature.registered_features
broken_feature.clean()
broken_feature.registered_features
Out[11]:
[]
Last update:
October 28, 2023
Created: October 28, 2023
Created: October 28, 2023