Skip to main content

Batch Write

Context manager that buffers put and delete operations. Auto-chunks at 25 items (DynamoDB limit) and retries unprocessed items with exponential backoff.

Basic Usage

with orders.batch_write() as batch:
batch.put(user_id="usr_1", order_id="ord_1", total=100)
batch.put(user_id="usr_2", order_id="ord_2", total=200)
batch.delete(user_id="usr_3", order_id="ord_3")
# All operations execute on context manager exit
warning

Operations are only executed when the with block exits normally. If an exception occurs inside the block, nothing is sent to DynamoDB.