Ligare.platform.feature_flag

Ligare.platform.feature_flag.CacheFeatureFlag

alias of FeatureFlag

class Ligare.platform.feature_flag.CachingFeatureFlagRouter(logger)[source]
__init__(logger)[source]
feature_is_cached(name)[source]
feature_is_enabled(name, default=False)[source]

Determine whether a feature flag is enabled or disabled.

Subclasses should call this method to validate parameters and use cached values.

Parameters:
  • name (str) – The feature flag to check.

  • default (bool) – If the feature flag is not in the in-memory dictionary of flags, this is the default value to return. The default parameter value when not specified is False.

Return bool:

If True, the feature is enabled. If False, the feature is disabled.

Return type:

bool

get_feature_flags(names=None)[source]

Get all feature flags and their status.

Return type:

Sequence[TypeVar(TFeatureFlag, bound= FeatureFlag, covariant=True)]

Params list[str] | None names:

Get only the flags contained in this list.

Return tuple[TFeatureFlag]:

An immutable sequence (a tuple) of feature flags.

If names is None this sequence contains _all_ feature flags in the cache. Otherwise, the list is filtered.

set_feature_is_enabled(name, is_enabled)[source]

Enables or disables a feature flag in the in-memory dictionary of feature flags.

Subclasses should call this method to validate parameters and cache values.

Parameters:
  • name (str) – The feature flag to check.

  • is_enabled (bool) – Whether the feature flag is to be enabled or disabled.

Return FeatureFlagChange:

An object representing the previous and new values of the changed feature flag.

Return type:

FeatureFlagChange

Ligare.platform.feature_flag.DBFeatureFlag

alias of FeatureFlag

class Ligare.platform.feature_flag.DBFeatureFlagRouter(feature_flag, scoped_session, logger)[source]
__init__(feature_flag, scoped_session, logger)[source]
feature_is_enabled(name, default=False, check_cache=True)[source]

Determine whether a feature flag is enabled or disabled. This method returns False if the feature flag does not exist in the database.

This method caches the value pulled from the database for the specified feature flag. It is only cached if the value is pulled from the database. If the flag does not exist, no value is cached.

Parameters:
  • name (str) – The feature flag to check.

  • default (bool) – The default value to return when a flag does not exist.

  • check_cache (bool) – Whether to use the cached value if it is cached. The default is True. If the cache is not checked, the new value pulled from the database will be cached.

Return type:

bool

get_feature_flags(names=None)[source]

Get all feature flags and their status from the database. This methods updates the cache to the values retrieved from the database. :rtype: Sequence[TypeVar(TFeatureFlag, bound= FeatureFlag, covariant=True)]

Parameters:

names (list[str] | None) – Get only the flags contained in this list.

Return tuple[TFeatureFlag]:

An immutable sequence (a tuple) of feature flags.

If names is None this sequence contains _all_ feature flags in the database. Otherwise, the list is filtered.

set_feature_is_enabled(name, is_enabled)[source]

Enable or disable a feature flag in the database.

This method caches the value of is_enabled for the specified feature flag unless saving to the database fails.

Parameters:
  • name (str) – The feature flag to check.

  • is_enabled (bool) – Whether the feature flag is to be enabled or disabled.

Return FeatureFlagChange:

An object representing the previous and new values of the changed feature flag.

Return type:

FeatureFlagChange

class Ligare.platform.feature_flag.FeatureFlag(name, enabled)[source]
__init__(name, enabled)
enabled: bool
name: str
class Ligare.platform.feature_flag.FeatureFlagChange(name, old_value, new_value)[source]
__init__(name, old_value, new_value)
name: str
new_value: bool | None
old_value: bool | None
class Ligare.platform.feature_flag.FeatureFlagRouter[source]

The base feature flag router. All feature flag routers should extend this class.

abstract feature_is_enabled(name, default=False)[source]

Determine whether a feature flag is enabled or disabled.

Parameters:
  • name (str) – The name of the feature flag.

  • default (bool) – A default value to return for cases where a feature flag may not exist. Defaults to False.

Return bool:

If True, the feature is enabled. If False, the feature is disabled.

Return type:

bool

abstract get_feature_flags(names=None)[source]

Get all feature flags and whether they are enabled. If names is not None, this only returns the enabled state of the flags in the list. :rtype: Sequence[TypeVar(TFeatureFlag, bound= FeatureFlag, covariant=True)]

Parameters:

names (list[str] | None) – Get only the flags contained in this list.

Return tuple[TFeatureFlag]:

An immutable sequence (a tuple) of feature flags.

If names is None this sequence contains _all_ feature flags. Otherwise, the list is filtered.

abstract set_feature_is_enabled(name, is_enabled)[source]

Enable or disable a feature flag.

Parameters:
  • name (str) – The name of the feature flag.

  • is_enabled (bool) – If True, the feature is enabled. If False, the feature is disabled.

Return FeatureFlagChange:

An object representing the previous and new values of the changed feature flag.

Return type:

FeatureFlagChange

Ligare.platform.feature_flag.feature_flag(feature_flag_name, *, enabled_callback=<function <lambda>>, disabled_callback=<function <lambda>>)[source]
Return type:

Callable[..., Callable[..., Any]]

Modules

caching_feature_flag_router

database

db_feature_flag_router

decorators

feature_flag_router