boto3.dynamodb.conditions

Module Contents

ATTR_NAME_REGEX
class ConditionBase(*values)

Bases:object

expression_format =
expression_operator =
has_grouped_values = False
__and__(self, other)
__or__(self, other)
__invert__(self)
get_expression(self)
__eq__(self, other)
__ne__(self, other)
class AttributeBase(name)

Bases:object

__and__(self, value)
__or__(self, value)
__invert__(self)
eq(self, value)

Creates a condition where the attribute is equal to the value.

Parameters:value – The value that the attribute is equal to.
lt(self, value)

Creates a condition where the attribute is less than the value.

Parameters:value – The value that the attribute is less than.
lte(self, value)
Creates a condition where the attribute is less than or equal to the
value.
Parameters:value – The value that the attribute is less than or equal to.
gt(self, value)

Creates a condition where the attribute is greater than the value.

Parameters:value – The value that the attribute is greater than.
gte(self, value)
Creates a condition where the attribute is greater than or equal to
the value.
Parameters:value – The value that the attribute is greater than or equal to.
begins_with(self, value)

Creates a condition where the attribute begins with the value.

Parameters:value – The value that the attribute begins with.
between(self, low_value, high_value)

Creates a condition where the attribute is greater than or equal to the low value and less than or equal to the high value.

Parameters:
  • low_value – The value that the attribute is greater than.
  • high_value – The value that the attribute is less than.
__eq__(self, other)
__ne__(self, other)
class ConditionAttributeBase(*values)

Bases:boto3.dynamodb.conditions.ConditionBase, boto3.dynamodb.conditions.AttributeBase

This base class is for conditions that can have attribute methods.

One example is the Size condition. To complete a condition, you need to apply another AttributeBase method like eq().

__eq__(self, other)
__ne__(self, other)
class ComparisonCondition

Bases:boto3.dynamodb.conditions.ConditionBase

expression_format = {0} {operator} {1}
class Equals

Bases:boto3.dynamodb.conditions.ComparisonCondition

expression_operator = =
class NotEquals

Bases:boto3.dynamodb.conditions.ComparisonCondition

expression_operator = <>
class LessThan

Bases:boto3.dynamodb.conditions.ComparisonCondition

expression_operator = <
class LessThanEquals

Bases:boto3.dynamodb.conditions.ComparisonCondition

expression_operator = <=
class GreaterThan

Bases:boto3.dynamodb.conditions.ComparisonCondition

expression_operator = >
class GreaterThanEquals

Bases:boto3.dynamodb.conditions.ComparisonCondition

expression_operator = >=
class In

Bases:boto3.dynamodb.conditions.ComparisonCondition

expression_operator = IN
has_grouped_values = True
class Between

Bases:boto3.dynamodb.conditions.ConditionBase

expression_operator = BETWEEN
expression_format = {0} {operator} {1} AND {2}
class BeginsWith

Bases:boto3.dynamodb.conditions.ConditionBase

expression_operator = begins_with
expression_format = {operator}({0}, {1})
class Contains

Bases:boto3.dynamodb.conditions.ConditionBase

expression_operator = contains
expression_format = {operator}({0}, {1})
class Size

Bases:boto3.dynamodb.conditions.ConditionAttributeBase

expression_operator = size
expression_format = {operator}({0})
class AttributeType

Bases:boto3.dynamodb.conditions.ConditionBase

expression_operator = attribute_type
expression_format = {operator}({0}, {1})
class AttributeExists

Bases:boto3.dynamodb.conditions.ConditionBase

expression_operator = attribute_exists
expression_format = {operator}({0})
class AttributeNotExists

Bases:boto3.dynamodb.conditions.ConditionBase

expression_operator = attribute_not_exists
expression_format = {operator}({0})
class And

Bases:boto3.dynamodb.conditions.ConditionBase

expression_operator = AND
expression_format = ({0} {operator} {1})
class Or

Bases:boto3.dynamodb.conditions.ConditionBase

expression_operator = OR
expression_format = ({0} {operator} {1})
class Not

Bases:boto3.dynamodb.conditions.ConditionBase

expression_operator = NOT
expression_format = ({operator} {0})
class Key

Bases:boto3.dynamodb.conditions.AttributeBase

class Attr

Bases:boto3.dynamodb.conditions.AttributeBase

Represents an DynamoDB item’s attribute.

ne(self, value)

Creates a condition where the attribute is not equal to the value

Parameters:value – The value that the attribute is not equal to.
is_in(self, value)

Creates a condition where the attribute is in the value,

Parameters:value (list) – The value that the attribute is in.
exists(self)

Creates a condition where the attribute exists.

not_exists(self)

Creates a condition where the attribute does not exist.

contains(self, value)

Creates a condition where the attribute contains the value.

Parameters:value – The value the attribute contains.
size(self)

Creates a condition for the attribute size.

Note another AttributeBase method must be called on the returned size condition to be a valid DynamoDB condition.

attribute_type(self, value)

Creates a condition for the attribute type.

Parameters:value – The type of the attribute.
BuiltConditionExpression
class ConditionExpressionBuilder

Bases:object

This class is used to build condition expressions with placeholders

_get_name_placeholder(self)
_get_value_placeholder(self)
reset(self)

Resets the placeholder name and values

build_expression(self, condition, is_key_condition=False)

Builds the condition expression and the dictionary of placeholders.

Parameters:
  • condition (ConditionBase) – A condition to be built into a condition expression string with any necessary placeholders.
  • is_key_condition (Boolean) – True if the expression is for a KeyConditionExpression. False otherwise.
Return type:

(string, dict, dict)

Returns:

Will return a string representing the condition with placeholders inserted where necessary, a dictionary of placeholders for attribute names, and a dictionary of placeholders for attribute values. Here is a sample return value:

(‘#n0 = :v0’, {‘#n0’: ‘myattribute’}, {‘:v1’: ‘myvalue’})

_build_expression(self, condition, attribute_name_placeholders, attribute_value_placeholders, is_key_condition)
_build_expression_component(self, value, attribute_name_placeholders, attribute_value_placeholders, has_grouped_values, is_key_condition)
_build_name_placeholder(self, value, attribute_name_placeholders)
_build_value_placeholder(self, value, attribute_value_placeholders, has_grouped_values=False)