featuremanagement package

Subpackages

Module contents

Feature management library for Python.

class featuremanagement.EvaluationEvent(feature_flag: FeatureFlag | None)

Represents a feature flag evaluation event.

class featuremanagement.FeatureFilter

Parent class for all feature filters.

static alias(alias: str) → Callable[[...], Any]

Decorator to set the alias for the filter.

Parameters:

alias (str) – Alias for the filter.

Returns:

Decorator.

Return type:

Callable

abstractmethod evaluate(context: Mapping[Any, Any], **kwargs: Any) → bool

Determine if the feature flag is enabled for the given context.

Parameters:

context (Mapping) – Context for the feature flag.

property name: str

Get the name of the filter.

Returns:

Name of the filter, or alias if it exists.

Return type:

str

class featuremanagement.FeatureFlag

Represents a feature flag.

property allocation: Allocation | None

Get the allocation for the feature flag.

Returns:

Allocation for the feature flag.

Return type:

Allocation

property conditions: FeatureConditions

Get the conditions for the feature flag.

Returns:

Conditions for the feature flag.

Return type:

FeatureConditions

classmethod convert_from_json(json_value: Mapping[str, Any]) → FeatureFlag

Convert a JSON object to FeatureFlag.

Parameters:

json_value (dict) – JSON object

Returns:

FeatureFlag.

Return type:

FeatureFlag

property enabled: bool

Get the status of the feature flag.

Returns:

Status of the feature flag.

Return type:

bool

property name: str

Get the name of the feature flag.

Returns:

Name of the feature flag.

Return type:

str

property telemetry: Telemetry

Get the telemetry configuration for the feature flag.

Returns:

Telemetry for the feature flag.

Return type:

Telemetry

property variants: List[VariantReference] | None

Get the variants for the feature flag.

Returns:

Variants for the feature flag.

Return type:

list[VariantReference]

class featuremanagement.FeatureManager(configuration: Mapping[str, Any], **kwargs: Any)

Feature Manager that determines if a feature flag is enabled for the given context.

Parameters:

configuration (Mapping) – Configuration object.

Keyword Arguments:
  • feature_filters (list[FeatureFilter]) – Custom filters to be used for evaluating feature flags.

  • on_feature_evaluated (Callable[EvaluationEvent]) – Callback function to be called when a feature flag is evaluated.

  • targeting_context_accessor (Callable[[], TargetingContext]) – Callback function to get the current targeting context if one isn’t provided.

get_variant(feature_flag_id: str, **kwargs: Any) → Variant | None
get_variant(feature_flag_id: str, user_id: str | TargetingContext, **kwargs: Any) → Variant | None

Determine the variant for the given context.

Parameters:
  • feature_flag_id (str) – Name of the feature flag

  • args – Optional positional user identifier or TargetingContext.

Returns:

Variant instance.

Return type:

Variant

is_enabled(feature_flag_id: str, **kwargs: Any) → bool
is_enabled(feature_flag_id: str, user_id: str | TargetingContext, **kwargs: Any) → bool

Determine if the feature flag is enabled for the given context.

Parameters:
  • feature_flag_id (str) – Name of the feature flag.

  • args – Optional positional user identifier or TargetingContext.

Returns:

True if the feature flag is enabled for the given context.

Return type:

bool

class featuremanagement.TargetingContext(user_id: str = '', groups: Sequence[str] = ())

Represents the context for targeting a feature flag.

groups: Sequence[str]

The users groups.

Type:

Sequence[str]

user_id: str

The user ID.

Type:

str

class featuremanagement.TargetingFilter

Feature Filter that determines if the user is targeted for the feature flag.

evaluate(context: Mapping[Any, Any], **kwargs: Any) → bool

Determine if the feature flag is enabled for the given context.

Keyword Arguments:

context (Mapping) – Context for evaluating the user/group.

Returns:

True if the user is targeted for the feature flag.

Return type:

bool

class featuremanagement.TimeWindowFilter

Feature Filter that determines if the current time is within the time window.

evaluate(context: Mapping[Any, Any], **kwargs: Any) → bool

Determine if the feature flag is enabled for the given context.

Keyword Arguments:

context (Mapping) – Mapping with the Start and End time for the feature flag.

Returns:

True if the current time is within the time window.

Return type:

bool

class featuremanagement.Variant(name: str, configuration: Any)

A class representing a variant configuration assigned by a feature flag.

Parameters:
  • name (str) – The name of the variant

  • configuration (dict) – The configuration of the variant.

property configuration: Any

The configuration of the variant. :rtype: Any

property name: str

The name of the variant. :rtype: str

class featuremanagement.VariantAssignmentReason(*values)

Represents an assignment reason.

DEFAULT_WHEN_DISABLED = 'DefaultWhenDisabled'
DEFAULT_WHEN_ENABLED = 'DefaultWhenEnabled'
GROUP = 'Group'
NONE = 'None'
PERCENTILE = 'Percentile'
USER = 'User'