Skip to main content

Filter Operators

Filter operators are used in .filter(), condition=, and condition_or=. The syntax follows the pattern attribute__operator=value.

Available Operators

OperatorDynamoDB functionExample
eq= :valstatus__eq="PENDING"
neq<> :valstatus__neq="CANCELLED"
gt> :valtotal__gt=100
gte>= :valtotal__gte=100
lt< :valtotal__lt=500
lte<= :valtotal__lte=500
betweenBETWEEN :a AND :btotal__between=[100, 500]
begins_withbegins_with(attr, :val)name__begins_with="John"
containscontains(attr, :val)tags__contains="urgent"
not_containsNOT contains(attr, :val)tags__not_contains="old"
existsattribute_exists(attr)email__exists=True
not_existsattribute_not_exists(attr)email__not_exists=True
inattr IN (:a, :b, ...)status__in=["PENDING", "DRAFT"]
not_begins_withNOT begins_with(attr, :val)name__not_begins_with="test_"
typeattribute_type(attr, :val)data__type="M"
sizesize(attr) <op> :valitems__size__gt=0

The size Operator

The size operator is special. It applies the DynamoDB size() function to the attribute and then uses another operator for comparison.

# Check if a list is not empty
orders.query(user_id="usr_123").filter(items__size__gt=0)

# Check if a map has between 1 and 10 elements
orders.query(user_id="usr_123").filter(metadata__size__between=[1, 10])

Nested Attributes

You can use dot notation to filter by nested attributes in Maps or specific indexes in Lists.

# Nested Map attribute
results = orders.query(user_id="usr_123").filter(address.city__eq="Lima")

# Specific List index
results = orders.query(user_id="usr_123").filter(items[0].qty__gt=5)

Multiple Filters

Multiple filters in a single .filter() call are automatically combined using AND logic.

results = orders.query(user_id="usr_123").filter(
status__eq="PENDING",
total__gte=100,
created_at__begins_with="2025"
)
# Generates: #status = :v0 AND #total >= :v1 AND #created_at begins_with(:v2)