AWS DynamoDB utility for parsing DynamoDB responses
Project description
AWS DynamoDB Parser
AWS DynamoDB utility for parsing DynamoDB responses
Installation
pip install aws-dynamodb-parser
Package Contents
parse
parse
is the main method exposed for parsing DynamoDB responses when using boto3
.
The parse
function can handle all of the data types AWS DynamoDB supports as of October 2020.
Examples
Assuming we have a table TABLE_NAME
containing the following entries, with id
set as the partition key and timestamp
as the sort key.
All three fields included are strings.
id | timestamp | name |
---|---|---|
a77b5fc0-75cb-408c-bebf-863873506cce | 2020-10-01 13:13:47.388492 | First test entry |
a77b5fc0-75cb-408c-bebf-863873506cce | 2020-10-01 13:15:25.376589 | Second test entry |
fa853ff0-706e-45db-b6ae-aa6a8a1f7856 | 2020-10-01 13:16:47.720778 | Third test entry |
Parsing the result from a get_item
request:
import boto3
from aws_dynamodb_parser import parse
dynamodb_client = boto3.client("dynamodb")
response = dynamodb_client.get_item(
TableName="TABLE_NAME",
Key={
"id": {"S": "a77b5fc0-75cb-408c-bebf-863873506cce"},
"timestamp": {"S": "2020-10-01 13:13:47.388492"}
}
)
item = response.get("Item", {})
print(item)
# {'id': {'S': 'a77b5fc0-75cb-408c-bebf-863873506cce'}, 'timestamp': {'S': '2020-10-01 13:13:47.388492'}, 'name': {'S': 'First test entry'}}
entry = parse(item)
print(entry)
# {'id': 'a77b5fc0-75cb-408c-bebf-863873506cce', 'timestamp': '2020-10-01 13:13:47.388492', 'name': 'First test entry'}
Parsing the result from a query
request:
import boto3
from aws_dynamodb_parser import parse
dynamodb_client = boto3.client("dynamodb")
response = dynamodb_client.query(
TableName="TABLE_NAME",
KeyConditionExpression="#id = :id",
ExpressionAttributeNames={
"#id": "id"
},
ExpressionAttributeValues={
":id": {"S": "a77b5fc0-75cb-408c-bebf-863873506cce"}
}
)
items = response.get("Items", [])
print(items)
# [{'id': {'S': 'a77b5fc0-75cb-408c-bebf-863873506cce'}, 'timestamp': {'S': '2020-10-01 13:13:47.388492'}, 'name': {'S': 'First test entry'}}, {'id': {'S': 'a77b5fc0-75cb-408c-bebf-863873506cce'}, 'timestamp': {'S': '2020-10-01 13:15:25.376589'}, 'name': {'S': 'Second test entry'}}]
entries = parse(items)
print(entries)
# [{'id': 'a77b5fc0-75cb-408c-bebf-863873506cce', 'timestamp': '2020-10-01 13:13:47.388492, 'name': 'First test entry'}, {'id': 'a77b5fc0-75cb-408c-bebf-863873506cce', 'timestamp': '2020-10-01 13:15:25.376589', 'name': 'Second test entry'}]
Documentation
Users can get the docstring help by running:
from aws_dynamodb_parser import parse
help(parse)
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for aws-dynamodb-parser-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10dd593bb7eb2c4a3aed3012813ba4c966df0d64e5bf4dbd809734e03bb7c006 |
|
MD5 | e1770e866019d6fffe87936ecef8f612 |
|
BLAKE2b-256 | 8952d3a5320dee7dc6c499fd3ae6aad5a555803479a95d9e95a3a2093b3c6a1e |
Close
Hashes for aws_dynamodb_parser-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f75eae4b4be149bf72107be7ea4fd6dd9ceedf99f8ef25d2de53cdcc1a43c1d |
|
MD5 | 8d7cf7ae9292b0e6f5feeef9661a19b4 |
|
BLAKE2b-256 | 5bb511032d4975d840d9e7888677a035baaab2a68a9adf6e878367733c8de273 |