feat(dynamodb): add key_schema parameter to read_items to bypass Desc…#3352
Merged
Conversation
…ribeTable (aws#2396) Signed-off-by: Jagan Nalla <jagannalla1@gmail.com>
4ff30ec to
fecc402
Compare
kukushking
requested changes
Jun 14, 2026
kukushking
left a comment
Collaborator
There was a problem hiding this comment.
Please update the docstring with the new key_schema parameter. Make sure to cover why it is added to help other users know that they can skip DescribeTable call.
Thank you!
Signed-off-by: Jagan Nalla <jagannalla1@gmail.com>
kukushking
approved these changes
Jun 15, 2026
Collaborator
|
Thank you @jagannalla ! |
Contributor
Author
|
Hi @kukushking, thank you for merging the PR! Glad to have this improvement included. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR resolves #2396 by introducing an optional
key_schemaparameter to thewr.dynamodb.read_itemsfunction.Problem:
Currently,
wr.dynamodb.read_itemsperforms an implicitDescribeTableAPI call under the hood on every invocation to resolve the table's hash and range keys. In loops, high-traffic scripts, or memory/time-constrained environments (like AWS Lambda), this redundant lookup:Solution:
Added an optional
key_schemaparameter to theread_itemsmethod and its corresponding type stub overloads.key_schemais supplied by the user (e.g.[{"AttributeName": "key", "KeyType": "HASH"}]), the library skips the costlyDescribeTableAPI request entirely and uses the provided schema.key_schemais omitted, the library defaults to its existing behavior of callingDescribeTabledynamically, ensuring 100% backward compatibility.Related Issue
Closes #2396
Type of Change
How Has This Been Tested?
Automated Tests:
Added a comprehensive unit test suite in
tests/unit/test_moto.pynamedtest_dynamodb_read_items_with_key_schemato verify:read_itemsworks flawlessly and parses records exactly as expected whenkey_schemais provided.DescribeTablecalls are made under the hood whenkey_schemais supplied.DescribeTableis called exactly once whenkey_schemais omitted.All 44 mocked unit tests passed successfully:
.venv/bin/pytest tests/unit/test_moto.py ======================== 44 passed in 4.30s ========================