awswrangler.dynamodb.execute_statement¶
- awswrangler.dynamodb.execute_statement(statement: str, parameters: list[Any] | None = None, consistent_read: bool = False, boto3_session: Session | None = None) Iterator[list[dict[str, Any]]] | None ¶
Run a PartiQL statement against a DynamoDB table.
- Parameters:
statement (
str
) – The PartiQL statement.parameters (
list
[Any
] |None
) – The list of PartiQL parameters. These are applied to the statement in the order they are listed.consistent_read (
bool
) – The consistency of a read operation. If True, then a strongly consistent read is used. False by default.boto3_session (
Session
|None
) – Boto3 Session. If None, the default boto3 Session is used.
- Return type:
Iterator
[list
[dict
[str
,Any
]]] |None
- Returns:
An iterator of the items from the statement response, if any.
Examples
Insert an item
>>> import awswrangler as wr >>> wr.dynamodb.execute_statement( ... statement="INSERT INTO movies VALUE {'title': ?, 'year': ?, 'info': ?}", ... parameters=[title, year, {"plot": plot, "rating": rating}], ... )
Select items
>>> wr.dynamodb.execute_statement( ... statement="SELECT * FROM movies WHERE title=? AND year=?", ... parameters=[title, year], ... )
Update items
>>> wr.dynamodb.execute_statement( ... statement="UPDATE movies SET info.rating=? WHERE title=? AND year=?", ... parameters=[rating, title, year], ... )
Delete items
>>> wr.dynamodb.execute_statement( ... statement="DELETE FROM movies WHERE title=? AND year=?", ... parameters=[title, year], ... )