Skip to content

Schema

CLASS DESCRIPTION
FeaturesValidator

Validates each feature and calls RulesValidator to validate its rules

ModuloRangeValues

Possible values when using modulo range rule

RulesValidator

Validates each rule and calls ConditionsValidator to validate each rule's conditions

SchemaValidator

Validates feature flag schema configuration

TimeKeys

Possible keys when using time rules

TimeValues

Possible values when using time rules

FeaturesValidator

FeaturesValidator(
    schema: dict,
    logger: logging.Logger | Logger | None = None,
)

Bases: BaseValidator

Validates each feature and calls RulesValidator to validate its rules

Source code in aws_lambda_powertools/utilities/feature_flags/schema.py
227
228
229
def __init__(self, schema: dict, logger: logging.Logger | Logger | None = None):
    self.schema = schema
    self.logger = logger or LOGGER

ModuloRangeValues

Bases: Enum

Possible values when using modulo range rule

RulesValidator

RulesValidator(
    feature: dict[str, Any],
    boolean_feature: bool,
    logger: logging.Logger | Logger | None = None,
)

Bases: BaseValidator

Validates each rule and calls ConditionsValidator to validate each rule's conditions

Source code in aws_lambda_powertools/utilities/feature_flags/schema.py
258
259
260
261
262
263
264
265
266
267
268
def __init__(
    self,
    feature: dict[str, Any],
    boolean_feature: bool,
    logger: logging.Logger | Logger | None = None,
):
    self.feature = feature
    self.feature_name = next(iter(self.feature))
    self.rules: dict | None = self.feature.get(RULES_KEY)
    self.logger = logger or LOGGER
    self.boolean_feature = boolean_feature

SchemaValidator

SchemaValidator(
    schema: dict[str, Any],
    logger: logging.Logger | Logger | None = None,
)

Bases: BaseValidator

Validates feature flag schema configuration

RAISES DESCRIPTION
SchemaValidationError

When schema doesn't conform with feature flag schema

Schema

Feature object

A dictionary containing default value and rules for matching. The value MUST be an object and MIGHT contain the following members:

  • default: bool | JSONType. Defines default feature value. This MUST be present
  • boolean_type: bool. Defines whether feature has non-boolean value (JSONType). This MIGHT be present
  • rules: dict[str, dict]. Rules object. This MIGHT be present

JSONType being any JSON primitive value: str | int | float | bool | None | dict[str, Any] | list[Any]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
    "my_feature": {
        "default": true,
        "rules": {}
    },
    "my_non_boolean_feature": {
        "default": {"group": "read-only"},
        "boolean_type": false,
        "rules": {}
    }
}

Rules object

A dictionary with each rule and their conditions that a feature might have. The value MIGHT be present, and when defined it MUST contain the following members:

  • when_match: bool | JSONType. Defines value to return when context matches conditions
  • conditions: list[dict]. Conditions object. This MUST be present
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
{
    "my_feature": {
        "default": true,
        "rules": {
            "tenant id equals 345345435": {
                "when_match": false,
                "conditions": []
            }
        }
    },
    "my_non_boolean_feature": {
        "default": {"group": "read-only"},
        "boolean_type": false,
        "rules": {
            "tenant id equals 345345435": {
                "when_match": {"group": "admin"},
                "conditions": []
            }
        }
    }
}

Conditions object

A list of dictionaries containing conditions for a given rule. The value MUST contain the following members:

  • action: str. Operation to perform to match a key and value. The value MUST be either EQUALS, STARTSWITH, ENDSWITH, KEY_IN_VALUE KEY_NOT_IN_VALUE VALUE_IN_KEY VALUE_NOT_IN_KEY

  • key: str. Key in given context to perform operation

  • value: Any. Value in given context that should match action operation.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
    "my_feature": {
        "default": true,
        "rules": {
            "tenant id equals 345345435": {
                "when_match": false,
                "conditions": [
                    {
                        "action": "EQUALS",
                        "key": "tenant_id",
                        "value": "345345435",
                    }
                ]
            }
        }
    }
}
Source code in aws_lambda_powertools/utilities/feature_flags/schema.py
201
202
203
204
205
206
207
208
def __init__(self, schema: dict[str, Any], logger: logging.Logger | Logger | None = None):
    self.schema = schema
    self.logger = logger or LOGGER

    # Validators are designed for modular testing
    # therefore we link the custom logger with global LOGGER
    # so custom validators can use them when necessary
    SchemaValidator._link_global_logger(self.logger)

TimeKeys

Bases: Enum

Possible keys when using time rules

TimeValues

Bases: Enum

Possible values when using time rules