John Sheehan
John Sheehan

Reputation: 78114

How do I loop over all items in a DynamoDB table using boto?

I'd like to query a DynamoDB table and retrieve all the items and loop over them using boto. How do I structure a query or scan that returns everything in the table?

Upvotes: 6

Views: 8576

Answers (1)

Steffen Opel
Steffen Opel

Reputation: 64741

Preliminary support for the Scan API had been added to boto's layer2 for DynamoDB by Chris Moyer in commit 522e0548 (Added scan to layer2 and Table) and has meanwhile been updated by Mitch Garnaat in commit adeb7151 (Cleaned up the scan method on Layer2 and Table.) to hide the layer1 details and enable intuitive querying - the respective issue #574 is currently scheduled to be released with boto 2.3.

A usage sample is implicitly included via tests/dynamodb/test_layer2.py:

# Try scans
results = table.scan([('Tags', 'CONTAINS', 'table')])
n = 0
for item in results:
    n += 1
assert n == 2

Upvotes: 3

Related Questions