Strategy

class UnleashClient.strategies.Strategy(constraints: list = [], parameters: dict = {}, segment_ids: list | None = None, global_segments: dict | None = None, variants: list | None = None)

The parent class for default and custom strategies.

In general, default & custom classes should only need to override:

  • __init__() - Depending on the parameters your feature needs

  • apply() - Your feature provisioning

Parameters:
  • constraints – List of ‘constraints’ objects derived from strategy section (…from feature section) of /api/clients/features Unleash server response.

  • variants – List of ‘variant’ objects derived from strategy section (…from feature section) of /api/clients/features Unleash server response.

  • parameters – The ‘parameter’ objects from the strategy section (…from feature section) of /api/clients/features Unleash server response.

execute(context: dict | None = None) bool

Executes the strategies by:

  • Checking constraints

  • Applying the strategy

This is what UnleashClient calls when you run is_enabled()

Parameters:

context – Feature flag context.

Returns:

Feature flag result.

load_provisioning() list

Loads strategy provisioning from Unleash feature flag configuration.

This should parse the raw values in self.parameters into format Python can comprehend.

apply(context: dict | None = None) bool

Strategy implementation.

Parameters:

context – Feature flag context

Returns:

Feature flag result