Skip to content

Python utilities to work with AWS DynamoDB

Notifications You must be signed in to change notification settings

noize-e/dyno.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

Dyno.py

A python client designed to work with AWS DynamoDB following the SingleTable schema model.

Ops

PutItem

This operation requires a partition key and optionally a sort key.

from dypy.db import SingleItem
import uuid


item = SingleItem(pk='user@email.com', sk=uuid.uuid4().hex, name='Frank')

Create a new Table instance, call the put method passing the SingleItem object to execute the operation.

...

response = Table('TableName').put(item)

Use the ok attribute to validate if the request was successful.

...

if response.ok:
    print("Item saved", item.data())

Secure PutItem

The SecureItem prevents items overwriting.

from dypy.db import SecureItem

item = SecureItem(pk='user@email.com', sk=uuid.uuid4().hex, name='Frank')
response = Table('TableName').put(item)

DynamoDB-JSON Parse

Convert JSON to DynamoJSON

Usage

# shell command
dynamojson --dump 'your.json' 'TableName' 
[
  {
    "uid": 1,
    "salt": "$2B$12$Pfsv3Tw6Rakclh/Ustdc3U",
    "media": { 
      "content": "/media1/live-radio-session-1.m3u8",
    }
  }
]

Dump:

{
  "TableName": [
    {
      "PutRequest": {
        "Item": {
          "uid": {
            "N": "1"
          },
          "salt": {
            "S": "$2B$12$Pfsv3Tw6Rakclh/Ustdc3U"
          },
          "media": {
            "M": {
              "content": {
                "S": "/media1/live-radio-session-1.m3u8"
              }
            }
          }
        }
      }
    }
  ]
}