⚙ configuration / configuration_path¶
Configuring all feature flags at once. Or reconfiguring after initialization.
Usage configuration
¶
The configuration file must be defined as a toml. However, it is also possible to provide the configuration as a dict
directly.
In [1]:
Copied!
from fastfeatureflag.feature_flag import feature_flag
import toml
from fastfeatureflag.feature_flag import feature_flag
import toml
In [2]:
Copied!
toml_content = """
[feature_one]
activation="off"
response="Do not respond!"
"""
configuration = toml.loads(toml_content)
@feature_flag(name="feature_one", configuration=configuration)
def feature_one():
return "original feature one"
feature_one()
toml_content = """
[feature_one]
activation="off"
response="Do not respond!"
"""
configuration = toml.loads(toml_content)
@feature_flag(name="feature_one", configuration=configuration)
def feature_one():
return "original feature one"
feature_one()
Out[2]:
'Do not respond!'
In [3]:
Copied!
feature_one.clean()
feature_one.clean()
In [4]:
Copied!
toml_content = """
[feature_one]
activation="on"
response="Do not respond!"
"""
configuration = toml.loads(toml_content)
@feature_flag(name="feature_one", configuration=configuration)
def feature_one():
return "original feature one"
feature_one()
toml_content = """
[feature_one]
activation="on"
response="Do not respond!"
"""
configuration = toml.loads(toml_content)
@feature_flag(name="feature_one", configuration=configuration)
def feature_one():
return "original feature one"
feature_one()
Out[4]:
'original feature one'
In [5]:
Copied!
feature_one.clean()
feature_one.clean()
Environment variables¶
For easier handling, the configuration can also contain environment variables.
In [6]:
Copied!
toml_content = """
[feature_one]
activation="FEATURE_ONE"
response="Do not respond!"
"""
toml_content = """
[feature_one]
activation="FEATURE_ONE"
response="Do not respond!"
"""
In [7]:
Copied!
import os
os.environ["FEATURE_ONE"] = "off"
import os
os.environ["FEATURE_ONE"] = "off"
In [8]:
Copied!
configuration = toml.loads(toml_content)
@feature_flag(name="feature_one", configuration=configuration)
def feature_one():
return "original feature one"
feature_one()
configuration = toml.loads(toml_content)
@feature_flag(name="feature_one", configuration=configuration)
def feature_one():
return "original feature one"
feature_one()
Out[8]:
'Do not respond!'
In [9]:
Copied!
feature_one.clean()
import os
os.environ["FEATURE_ONE"] = "on"
feature_one.clean()
import os
os.environ["FEATURE_ONE"] = "on"
In [10]:
Copied!
configuration = toml.loads(toml_content)
@feature_flag(name="feature_one", configuration=configuration)
def feature_one():
return "original feature one"
feature_one()
configuration = toml.loads(toml_content)
@feature_flag(name="feature_one", configuration=configuration)
def feature_one():
return "original feature one"
feature_one()
Out[10]:
'original feature one'
Usage configuration_path
¶
Instead of the configuration directly, it is also possible to provide a path to a toml, containing the configuration
In [11]:
Copied!
import pathlib
@feature_flag(name="grouped_feature", configuration_path=pathlib.Path("sample_config.toml"))
def feature_one():
return "original feature one"
feature_one()
import pathlib
@feature_flag(name="grouped_feature", configuration_path=pathlib.Path("sample_config.toml"))
def feature_one():
return "original feature one"
feature_one()
Out[11]:
'Response defined by toml'
Of course, also the toml
file can contain environment variables.
Last update:
October 28, 2023
Created: October 28, 2023
Created: October 28, 2023