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

2024/7/27 16:50:18

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?

Answer

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
https://en.xdnf.cn/q/72836.html

Related Q&A

install pyopencv with pip on Mac OS X

I am trying to install pyopencv with pip in OS X Mountain Lion and it fails by import setuptools. Following is my work. what is "Library" in setuptools? I have not seen that before. I alread…

OpenCV remap interpolation error?

Im using opencv remap function to map an image to another coordinate system. However, my initial tests indicate that there are some issues with the interpolation. Here, I give a simple example of a co…

Installing python with python win32 extensions on a network drive

I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network dri…

Python pytest hangs. For instance, pytest --version simply hangs

The following hangs:PS C:\Users\Fowler> pytest --version Notes:I am in Windows 10. By hang, I mean at least 5 minutes of waiting for the pytest --version to return... While waiting for pytest, pyth…

PyQt4 signals and slots

I am writing my first Python app with PyQt4. I have a MainWindow and a Dialog class, which is a part of MainWindow class:self.loginDialog = LoginDialog();I use slots and signals. Heres a connection mad…

Masking a pandas DataFrame with a numpy array vs DataFrame

I want to use a 2D boolean mask to selectively alter some cells in a pandas DataFrame. I noticed that I cannot use a numpy array (successfully) as the mask, but I can use a DataFrame. More frustratin…

How to explode multiple columns, different types and different lengths?

Ive got a DF with columns of different time cycles (1/6, 3/6, 6/6 etc.) and would like to "explode" all the columns to create a new DF in which each row is a 1/6 cycle.from pyspark import Row…

How to convert \xXY encoded characters to UTF-8 in Python?

I have a text which contains characters such as "\xaf", "\xbe", which, as I understand it from this question, are ASCII encoded characters. I want to convert them in Python to their…

Pandas One hot encoding: Bundling together less frequent categories

Im doing one hot encoding over a categorical column which has some 18 different kind of values. I want to create new columns for only those values, which appear more than some threshold (lets say 1%), …

How to pass classs self through a flask.Blueprint.route decorator?

I am writing my websites backend using Flask and Python 2.7, and have run into a bit of a problem. I like to use classes to enclose my functions, it makes things neat for me and helps me keep everythin…