Scan¶
When given a Scan
, the connection will return a ScanResponse
:
>>> connection(Scan(table))
<LowVoltage.actions.scan.ScanResponse ...>
Items are accessed like this:
>>> connection(Scan(table)).items
[{u'a': 0, u'h': 7}, {u'a': 0, u'h': 8}, {u'h': 3, u'gr': 4, u'gh': 9}, {u'h': 2, u'gr': 6, u'gh': 4}, {u'a': 0, u'h': 9}, {u'h': 4, u'gr': 2, u'gh': 16}, {u'h': 6, u'gr': -2, u'gh': 36}, {u'h': 1, u'gr': 8, u'gh': 1}, {u'h': 0, u'gr': 10, u'gh': 0}, {u'h': 5, u'gr': 0, u'gh': 25}]
Note that items are returned in an undefined order.
See also the iterate_scan()
compound. And Actions vs. compounds in the user guide.
-
class
ScanResponse
¶ The Scan response.
-
consumed_capacity
¶ The capacity consumed by the request. If you used
return_consumed_capacity_total()
.Type: None
orConsumedCapacity
-
count
¶ The number of items matching the scan.
Type: None
or long
-
items
¶ The items matching the scan. Unless you used
Scan.select_count()
.Type: None
or list of dict
-
last_evaluated_key
¶ The key of the last item evaluated by the scan. If not None, it should be given to
exclusive_start_key()
is a subsequentScan
.The
iterate_scan()
compound does that for you.Type: None
or dict
-
scanned_count
¶ The number of item scanned during the scan. This can be different from
count
when usingfilter_expression()
.Type: None
or long
-
-
class
Scan
(table_name=None)¶ The Scan request.
Passing
table_name
to the constructor is like callingtable_name()
on the new instance.-
table_name
(table_name)¶ Set TableName. Mandatory, can also be set in the constructor.
>>> connection( ... Scan() ... .table_name(table) ... ) <LowVoltage.actions.scan.ScanResponse ...>
-
exclusive_start_key
(key)¶ Set ExclusiveStartKey. The request will only scan items that are after this key. This is typically the
last_evaluated_key
of a previous response.The
iterate_scan()
compound does that for you.>>> r = connection( ... Scan(table) ... .project("h") ... .limit(5) ... ) >>> r.items [{u'h': 7}, {u'h': 8}, {u'h': 3}, {u'h': 2}, {u'h': 9}] >>> r.last_evaluated_key {u'h': 9} >>> connection( ... Scan(table) ... .project("h") ... .exclusive_start_key({"h": 9}) ... ).items [{u'h': 4}, {u'h': 6}, {u'h': 1}, {u'h': 0}, {u'h': 5}]
-
expression_attribute_name
(synonym, name)¶ Add a synonym for an attribute name to ExpressionAttributeNames. Useful for attributes whose names don’t play well with ProjectionExpression, ConditionExpression or UpdateExpression because they contain a dot or brackets.
See
filter_expression()
for an example.
-
expression_attribute_value
(name, value)¶ Add a named value to ExpressionAttributeValues.
See
filter_expression()
for an example.
-
filter_expression
(expression)¶ Set the FilterExpression. The response will contain only items that match.
>>> connection( ... Scan(table) ... .filter_expression("#syn=:val") ... .expression_attribute_name("syn", "a") ... .expression_attribute_value("val", 42) ... ).items []
-
index_name
(index_name)¶ Set IndexName. The request will use this index instead of the table key.
>>> connection( ... Scan(table) ... .index_name("gsi") ... ).items [{u'h': 5, u'gr': 0, u'gh': 25}, {u'h': 3, u'gr': 4, u'gh': 9}, {u'h': 2, u'gr': 6, u'gh': 4}, {u'h': 4, u'gr': 2, u'gh': 16}, {u'h': 6, u'gr': -2, u'gh': 36}, {u'h': 1, u'gr': 8, u'gh': 1}, {u'h': 0, u'gr': 10, u'gh': 0}]
-
limit
(limit)¶ Set Limit. The request will scan at most this number of items.
See
exclusive_start_key()
for an example.
-
project
(*names)¶ Note that this function is variadic. See Variadic functions.
Add name(s) to ProjectionExpression. The request will return only projected attributes.
>>> connection(Scan(table).project("h")).items [{u'h': 7}, {u'h': 8}, {u'h': 3}, {u'h': 2}, {u'h': 9}, {u'h': 4}, {u'h': 6}, {u'h': 1}, {u'h': 0}, {u'h': 5}]
-
return_consumed_capacity_total
()¶ Set ReturnConsumedCapacity to TOTAL. The response will contain the total capacity consumed by this request.
>>> connection( ... Scan(table) ... .return_consumed_capacity_total() ... ).consumed_capacity.capacity_units 0.5
-
return_consumed_capacity_none
()¶ Set ReturnConsumedCapacity to NONE. The response will not contain the capacity consumed by this request.
>>> print connection( ... Scan(table) ... .return_consumed_capacity_none() ... ).consumed_capacity None
-
segment
(segment, total_segments)¶ Set Segment and TotalSegments for a parallel scan.
Items will be partitioned in
total_segments
segments of approximately the same size, and only the items of thesegment
-th segment will be returned in this request.parallelize_scan()
does that for you.>>> connection( ... Scan(table) ... .project("h") ... .segment(0, 2) ... ).items [{u'h': 7}, {u'h': 8}, {u'h': 3}, {u'h': 2}, {u'h': 9}, {u'h': 4}] >>> connection( ... Scan(table) ... .project("h") ... .segment(1, 2) ... ).items [{u'h': 6}, {u'h': 1}, {u'h': 0}, {u'h': 5}]
-
select_count
()¶ Set Select to COUNT. The response will contain only the count of matching items.
>>> r = connection(Scan(table).select_count()) >>> r.count 10L >>> print r.items None
-
select_all_attributes
()¶ Set Select to ALL_ATTRIBUTES. The response will contain all attributes of the matching items.
>>> connection(Scan(table).select_all_attributes()).items [{u'a': 0, u'h': 7}, {u'a': 0, u'h': 8}, {u'h': 3, u'gr': 4, u'gh': 9}, {u'h': 2, u'gr': 6, u'gh': 4}, {u'a': 0, u'h': 9}, {u'h': 4, u'gr': 2, u'gh': 16}, {u'h': 6, u'gr': -2, u'gh': 36}, {u'h': 1, u'gr': 8, u'gh': 1}, {u'h': 0, u'gr': 10, u'gh': 0}, {u'h': 5, u'gr': 0, u'gh': 25}]
-