PutItem

When given a PutItem, the connection will return a PutItemResponse:

>>> connection(PutItem(table, {"h": 0}))
<LowVoltage.actions.put_item.PutItemResponse ...>
class PutItemResponse

The PutItem response.

attributes

The previous attributes of the item you just put. If you used return_values_all_old().

Type:None or dict
consumed_capacity

The capacity consumed by the request. If you used return_consumed_capacity_total() or return_consumed_capacity_indexes().

Type:None or ConsumedCapacity
item_collection_metrics

Metrics about the collection of the item you just put. If a LSI was touched and you used return_item_collection_metrics_size().

Type:None or ItemCollectionMetrics
class PutItem(table_name=None, item=None)

The PutItem request.

Passing table_name to the constructor is like calling table_name() on the new instance. Passing item to the constructor is like calling item() on the new instance.

item(item)

Set Item. Mandatory, can also be set in the constructor.

>>> connection(
...   PutItem(table_name=table)
...     .item({"h": 0})
... )
<LowVoltage.actions.put_item.PutItemResponse ...>
table_name(table_name)

Set TableName. Mandatory, can also be set in the constructor.

>>> connection(
...   PutItem(item={"h": 0})
...     .table_name(table)
... )
<LowVoltage.actions.put_item.PutItemResponse ...>
condition_expression(expression)

Set the ConditionExpression, making the request conditional. It will raise a ConditionalCheckFailedException if the condition is not met.

>>> connection(
...   PutItem(table, {"h": 1})
...     .condition_expression("#syn=:val")
...     .expression_attribute_name("syn", "gr")
...     .expression_attribute_value("val", 8)
... )
<LowVoltage.actions.put_item.PutItemResponse ...>
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 condition_expression() for an example.

expression_attribute_value(name, value)

Add a named value to ExpressionAttributeValues.

See condition_expression() for an example.

return_consumed_capacity_indexes()

Set ReturnConsumedCapacity to INDEXES. The response will contain the capacity consumed by this request detailled on the table and the indexes.

>>> c = connection(
...   PutItem(table, {"h": 5, "gh": 5, "gr": 5})
...     .return_consumed_capacity_indexes()
... ).consumed_capacity
>>> c.capacity_units
3.0
>>> c.table.capacity_units
1.0
>>> c.global_secondary_indexes["gsi"].capacity_units
2.0
return_consumed_capacity_total()

Set ReturnConsumedCapacity to TOTAL. The response will contain the total capacity consumed by this request.

>>> connection(
...   PutItem(table, {"h": 4, "gh": 4, "gr": 4})
...     .return_consumed_capacity_total()
... ).consumed_capacity.capacity_units
3.0
return_consumed_capacity_none()

Set ReturnConsumedCapacity to NONE. The response will not contain the capacity consumed by this request.

>>> print connection(
...   PutItem(table, {"h": 6})
...     .return_consumed_capacity_none()
... ).consumed_capacity
None
return_item_collection_metrics_size()

Set ReturnItemCollectionMetrics to SIZE. If the table has a local secondary index, the response will contain metrics about the size of item collections that were touched.

>>> m = connection(
...   PutItem(table2, {"h": 0, "r1": 0, "r2": 1})
...     .return_item_collection_metrics_size()
... ).item_collection_metrics
>>> m.item_collection_key
{u'h': 0}
>>> m.size_estimate_range_gb
[0.0, 1.0]
return_item_collection_metrics_none()

Set ReturnItemCollectionMetrics to NONE. The response will not contain any item collection metrics.

>>> print connection(
...   PutItem(table2, {"h": 1, "r1": 0, "r2": 1})
...     .return_item_collection_metrics_none()
... ).item_collection_metrics
None
return_values_all_old()

Set ReturnValues to ALL_OLD. The response will contain all the attributes of the item in its previous state.

>>> connection(
...   PutItem(table, {"h": 2})
...     .return_values_all_old()
... ).attributes
{u'h': 2, u'gr': 6, u'gh': 4}
return_values_none()

Set ReturnValues to NONE. The response will not include the attributes of the item.

>>> print connection(
...   PutItem(table, {"h": 3})
...     .return_values_none()
... ).attributes
None