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
StringEqualsPath
(variable, value)¶ Creates a rule with the StringEqualsPath operator.
Parameters: Returns: Rule with StringEqualsPath operator.
Return type:
-
classmethod
StringLessThan
(variable, value)¶ Creates a rule with the StringLessThan operator.
Parameters: Returns: Rule with StringLessThan operator.
Return type:
-
classmethod
StringLessThanPath
(variable, value)¶ Creates a rule with the StringLessThanPath operator.
Parameters: Returns: Rule with StringLessThanPath operator.
Return type:
-
classmethod
StringGreaterThan
(variable, value)¶ Creates a rule with the StringGreaterThan operator.
Parameters: Returns: Rule with StringGreaterThan operator.
Return type:
-
classmethod
StringGreaterThanPath
(variable, value)¶ Creates a rule with the StringGreaterThanPath operator.
Parameters: Returns: Rule with StringGreaterThanPath operator.
Return type:
-
classmethod
StringLessThanEquals
(variable, value)¶ Creates a rule with the StringLessThanEquals operator.
Parameters: Returns: Rule with StringLessThanEquals operator.
Return type:
-
classmethod
StringLessThanEqualsPath
(variable, value)¶ Creates a rule with the StringLessThanEqualsPath operator.
Parameters: Returns: Rule with StringLessThanEqualsPath operator.
Return type:
-
classmethod
StringGreaterThanEquals
(variable, value)¶ Creates a rule with the StringGreaterThanEquals operator.
Parameters: Returns: Rule with StringGreaterThanEquals operator.
Return type:
-
classmethod
StringGreaterThanEqualsPath
(variable, value)¶ Creates a rule with the StringGreaterThanEqualsPath operator.
Parameters: Returns: Rule with StringGreaterThanEqualsPath operator.
Return type:
-
classmethod
NumericEquals
(variable, value)¶ Creates a rule with the NumericEquals operator.
Parameters: Returns: Rule with NumericEquals operator.
Return type:
-
classmethod
NumericEqualsPath
(variable, value)¶ Creates a rule with the NumericEqualsPath operator.
Parameters: Returns: Rule with NumericEqualsPath operator.
Return type:
-
classmethod
NumericLessThan
(variable, value)¶ Creates a rule with the NumericLessThan operator.
Parameters: Returns: Rule with NumericLessThan operator.
Return type:
-
classmethod
NumericLessThanPath
(variable, value)¶ Creates a rule with the NumericLessThanPath operator.
Parameters: Returns: Rule with NumericLessThanPath operator.
Return type:
-
classmethod
NumericGreaterThan
(variable, value)¶ Creates a rule with the NumericGreaterThan operator.
Parameters: Returns: Rule with NumericGreaterThan operator.
Return type:
-
classmethod
NumericGreaterThanPath
(variable, value)¶ Creates a rule with the NumericGreaterThanPath operator.
Parameters: Returns: Rule with NumericGreaterThanPath operator.
Return type:
-
classmethod
NumericLessThanEquals
(variable, value)¶ Creates a rule with the NumericLessThanEquals operator.
Parameters: Returns: Rule with NumericLessThanEquals operator.
Return type:
-
classmethod
NumericLessThanEqualsPath
(variable, value)¶ Creates a rule with the NumericLessThanEqualsPath operator.
Parameters: Returns: Rule with NumericLessThanEqualsPath operator.
Return type:
-
classmethod
NumericGreaterThanEquals
(variable, value)¶ Creates a rule with the NumericGreaterThanEquals operator.
Parameters: Returns: Rule with NumericGreaterThanEquals operator.
Return type:
-
classmethod
NumericGreaterThanEqualsPath
(variable, value)¶ Creates a rule with the NumericGreaterThanEqualsPath operator.
Parameters: Returns: Rule with NumericGreaterThanEqualsPath operator.
Return type:
-
classmethod
BooleanEquals
(variable, value)¶ Creates a rule with the BooleanEquals operator.
Parameters: Returns: Rule with BooleanEquals operator.
Return type:
-
classmethod
BooleanEqualsPath
(variable, value)¶ Creates a rule with the BooleanEqualsPath operator.
Parameters: Returns: Rule with BooleanEqualsPath operator.
Return type:
-
classmethod
TimestampEquals
(variable, value)¶ Creates a rule with the TimestampEquals operator.
Parameters: Returns: Rule with TimestampEquals operator.
Return type:
-
classmethod
TimestampEqualsPath
(variable, value)¶ Creates a rule with the TimestampEqualsPath operator.
Parameters: Returns: Rule with TimestampEqualsPath operator.
Return type:
-
classmethod
TimestampLessThan
(variable, value)¶ Creates a rule with the TimestampLessThan operator.
Parameters: Returns: Rule with TimestampLessThan operator.
Return type:
-
classmethod
TimestampLessThanPath
(variable, value)¶ Creates a rule with the TimestampLessThanPath operator.
Parameters: Returns: Rule with TimestampLessThanPath operator.
Return type:
-
classmethod
TimestampGreaterThan
(variable, value)¶ Creates a rule with the TimestampGreaterThan operator.
Parameters: Returns: Rule with TimestampGreaterThan operator.
Return type:
-
classmethod
TimestampGreaterThanPath
(variable, value)¶ Creates a rule with the TimestampGreaterThanPath operator.
Parameters: Returns: Rule with TimestampGreaterThanPath operator.
Return type:
-
classmethod
TimestampLessThanEquals
(variable, value)¶ Creates a rule with the TimestampLessThanEquals operator.
Parameters: Returns: Rule with TimestampLessThanEquals operator.
Return type:
-
classmethod
TimestampLessThanEqualsPath
(variable, value)¶ Creates a rule with the TimestampLessThanEqualsPath operator.
Parameters: Returns: Rule with TimestampLessThanEqualsPath operator.
Return type:
-
classmethod
TimestampGreaterThanEquals
(variable, value)¶ Creates a rule with the TimestampGreaterThanEquals operator.
Parameters: Returns: Rule with TimestampGreaterThanEquals operator.
Return type:
-
classmethod
TimestampGreaterThanEqualsPath
(variable, value)¶ Creates a rule with the TimestampGreaterThanEqualsPath operator.
Parameters: Returns: Rule with TimestampGreaterThanEqualsPath operator.
Return type:
-
classmethod
IsNull
(variable, value)¶ Creates a rule with the IsNull operator.
Parameters: Returns: Rule with IsNull operator.
Return type:
-
classmethod
IsPresent
(variable, value)¶ Creates a rule with the IsPresent operator.
Parameters: Returns: Rule with IsPresent operator.
Return type:
-
classmethod
IsString
(variable, value)¶ Creates a rule with the IsString operator.
Parameters: Returns: Rule with IsString operator.
Return type:
-
classmethod
IsNumeric
(variable, value)¶ Creates a rule with the IsNumeric operator.
Parameters: Returns: Rule with IsNumeric operator.
Return type:
-
classmethod
IsTimestamp
(variable, value)¶ Creates a rule with the IsTimestamp operator.
Parameters: Returns: Rule with IsTimestamp operator.
Return type:
-
classmethod
IsBoolean
(variable, value)¶ Creates a rule with the IsBoolean operator.
Parameters: Returns: Rule with IsBoolean operator.
Return type:
-
classmethod
StringMatches
(variable, value)¶ Creates a rule with the StringMatches operator.
Parameters: - variable (str) – Path to the variable to compare.
- value (str) – A string pattern that may contain one or more * characters to compare the value at variable to. The * character can be escaped using two backslashes. The comparison yields true if the variable matches the pattern, where * is a wildcard that matches zero or more characters.
Returns: Rule with StringMatches 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