Skip to content

EpicWink/dynamodb-serialise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DynamoDB value serialisation and deserialisation

Convert values from AWS DynamoDB to native Python types.

Makes more sensible decisions about numbers and binary values, at the cost of floating-point precision. Very lightweight.

Installation

pip install dynamodb-serialise

Usage

import dynamodb_serialise

dynamodb_serialise.deserialise(
    {"M": {"foo": {"N": "42"}, "bar": {"B": "c3BhbQ=="}}}
)
# {'foo': 42, 'bar': b'spam'}

dynamodb_serialise.serialise(
    {'foo': 42, 'bar': b'spam'}, bytes_to_base64=True
)
# {"M": {"foo": {"N": "42"}, "bar": {"B": "c3BhbQ=="}}}

Command-line

Can be run to transform values at the command-line, transforming stdin to stdout as JSON. Pass -d to deserialise instead of serialise.

The following example uses AWS CLI (aws) to produce DynamoDB values in lists of objects, jq to convert the scan result to full DynamoDB values, and dynamodb-serialise to convert to native types.

aws dynamodb scan \
  --table-name my-table \
  | jq '{ L: .Items | map({ M: . }) }' \
  | python3 -m dynamodb_serialise -d

About

AWS DynamoDB value serialisation and deserialisation

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages