Models

Allocation dataclass

Bases: _Validatable

Allocation represents the portion of an audience that is allocated to a particular variant.

Audience dataclass

Bases: _Validatable

An audience is a population of entities that all share a matching set of characteristics or, in the case of a default rule, no matching characteristics.

Entities within an audience are assigned to an allocation based on their respective identities.

determine_variant(rangekey)

Determines the variant that matches a given entity based on the position of its identity within the range of allocations within this audience.

matches(context)

Tests an entity to see if it matches the rule for inclusion in the audience.

Context

Bases: UserDict

Context contains contextual data for use by experiments in determining matching variants.

identity(keypath, seed)

Uses context data to calculate an identity for the given keypath and seed.

Parameters:
  • keypath (str) –

    A path to specifying the key of the value in the context that is to be used as the identity. Paths are in object notation (period-delimited).

  • seed (str) –

    A seed value that is combined with the key to produce an identity.

keypath has a special value, "random", that will return a random value for use as the identity. Seed has no effect if "random" is used as the keypath.

Identity values are cached so, the same keypath/seed pair will not be re-calculated if identity() is called again.

Raises:
  • KeyError

    If the keypath does not exist in the context or its corresponding value is None.

Experiment dataclass

Bases: _Validatable

Experiment represents a test that can be used to verify a hypothesis by bucketing entities into multiple variants.

determine_variant(context, override)

Determines which variant an entity should use by matching them against audience rules.

Audiences will be matched in the order in which they are defined.