Ligare.platform.feature_flag.db_feature_flag_router

Classes

DBFeatureFlagRouter(feature_flag, ...)

FeatureFlag(name, enabled, description)

FeatureFlagTable(base)

class Ligare.platform.feature_flag.db_feature_flag_router.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.db_feature_flag_router.FeatureFlag(name, enabled, description)[source]
__init__(name, enabled, description)
description: str | None
class Ligare.platform.feature_flag.db_feature_flag_router.FeatureFlagTable(base: TMetaBase)[source]
static __new__(cls, base)[source]
Return type:

type[FeatureFlagTableBase[TypeVar(TMetaBase, bound= DeclarativeMeta, covariant=True)]]

protocol Ligare.platform.feature_flag.db_feature_flag_router.FeatureFlagTableBase[source]

typing.Protocol.

Classes that implement this protocol must have the following methods / attributes:

__tablename__: str
description: str
enabled: bool
name: str