Choice Rules¶
This module defines the choice rules for a Choice state.
Use the add_choice()
method to add a branch to a Choice step.
my_choice_state.add_choice(
rule=ChoiceRule.BooleanEquals(variable=previous_state.output()["Success"], value=True),
next_step=happy_path
)
my_choice_state.add_choice(
ChoiceRule.BooleanEquals(variable=previous_state.output()["Success"], value=False),
next_step=sad_state
)
In this example, choice rules are added to the Choice state
my_choice_state
using add_choice()
.
Logic in a Choice state
is implemented with the help of Choice Rules. A Choice Rule encapsulates a
comparison, which contains the following:
- An input variable to compare
- The type of comparison
- The value to compare the variable to
The type of comparison is abstracted by the classes provided in this module. Multiple choice rules can be
compounded together using the And()
or
Or()
classes. A choice rule can be negated using
the Not()
class.
-
class
stepfunctions.steps.choice_rule.
Rule
(variable, operator, value)¶ Bases:
stepfunctions.steps.choice_rule.BaseRule
Class for creating a rule.
Parameters: Raises: ValueError
– If variable doesn’t start with ‘$’ValueError
– If value is not the appropriate datatype for the operator specified.
-
class
stepfunctions.steps.choice_rule.
CompoundRule
(operator, rules)¶ Bases:
stepfunctions.steps.choice_rule.BaseRule
Class for creating a compound rule.
Parameters: Raises: ValueError
– If any item in the rules list is not a BaseRule object.
-
class
stepfunctions.steps.choice_rule.
NotRule
(rule)¶ Bases:
stepfunctions.steps.choice_rule.BaseRule
Class for creating a negation rule.
Parameters: rules (BaseRule) – Rule to negate. Raises: ValueError
– If rule is not a BaseRule object.
-
class
stepfunctions.steps.choice_rule.
ChoiceRule
¶ Bases:
object
Factory class for creating a choice rule.
-
classmethod
StringEquals
(variable, value)¶ Creates a rule with the StringEquals operator.
Parameters: Returns: Rule with StringEquals operator.
Return type:
-
classmethod
StringLessThan
(variable, value)¶ Creates a rule with the StringLessThan operator.
Parameters: Returns: Rule with StringLessThan operator.
Return type:
-
classmethod
StringGreaterThan
(variable, value)¶ Creates a rule with the StringGreaterThan operator.
Parameters: Returns: Rule with StringGreaterThan operator.
Return type:
-
classmethod
StringLessThanEquals
(variable, value)¶ Creates a rule with the StringLessThanEquals operator.
Parameters: Returns: Rule with StringLessThanEquals operator.
Return type:
-
classmethod
StringGreaterThanEquals
(variable, value)¶ Creates a rule with the StringGreaterThanEquals operator.
Parameters: Returns: Rule with StringGreaterThanEquals operator.
Return type:
-
classmethod
NumericEquals
(variable, value)¶ Creates a rule with the NumericEquals operator.
Parameters: Returns: Rule with NumericEquals operator.
Return type:
-
classmethod
NumericLessThan
(variable, value)¶ Creates a rule with the NumericLessThan operator.
Parameters: Returns: Rule with NumericLessThan operator.
Return type:
-
classmethod
NumericGreaterThan
(variable, value)¶ Creates a rule with the NumericGreaterThan operator.
Parameters: Returns: Rule with NumericGreaterThan operator.
Return type:
-
classmethod
NumericLessThanEquals
(variable, value)¶ Creates a rule with the NumericLessThanEquals operator.
Parameters: Returns: Rule with NumericLessThanEquals operator.
Return type:
-
classmethod
NumericGreaterThanEquals
(variable, value)¶ Creates a rule with the NumericGreaterThanEquals operator.
Parameters: Returns: Rule with NumericGreaterThanEquals operator.
Return type:
-
classmethod
BooleanEquals
(variable, value)¶ Creates a rule with the BooleanEquals operator.
Parameters: Returns: Rule with BooleanEquals operator.
Return type:
-
classmethod
TimestampEquals
(variable, value)¶ Creates a rule with the TimestampEquals operator.
Parameters: Returns: Rule with TimestampEquals operator.
Return type:
-
classmethod
TimestampLessThan
(variable, value)¶ Creates a rule with the TimestampLessThan operator.
Parameters: Returns: Rule with TimestampLessThan operator.
Return type:
-
classmethod
TimestampGreaterThan
(variable, value)¶ Creates a rule with the TimestampGreaterThan operator.
Parameters: Returns: Rule with TimestampGreaterThan operator.
Return type:
-
classmethod
TimestampLessThanEquals
(variable, value)¶ Creates a rule with the TimestampLessThanEquals operator.
Parameters: Returns: Rule with TimestampLessThanEquals operator.
Return type:
-
classmethod
TimestampGreaterThanEquals
(variable, value)¶ Creates a rule with the TimestampGreaterThanEquals operator.
Parameters: Returns: Rule with TimestampGreaterThanEquals operator.
Return type:
-
classmethod
And
(rules)¶ Creates a compound rule with the And operator.
Parameters: rules (list(BaseRule)) – List of rules to compound together. Returns: Compound rule with And operator. Return type: CompoundRule
-
classmethod
Or
(rules)¶ Creates a compound rule with the Or operator.
Parameters: rules (list(BaseRule)) – List of rules to compound together. Returns: Compound rule with Or operator. Return type: CompoundRule
-
classmethod