-
-
Save fakabbir/fb4a0f37581e76a34585d8013052fd1c to your computer and use it in GitHub Desktop.
Coverts a standard Python dictionary to a Boto3 DynamoDB item
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
def dict_to_item(raw): | |
if type(raw) is dict: | |
resp = {} | |
for k,v in raw.iteritems(): | |
if type(v) is str: | |
resp[k] = { | |
'S': v | |
} | |
elif type(v) is int: | |
resp[k] = { | |
'I': str(v) | |
} | |
elif type(v) is dict: | |
resp[k] = { | |
'M': dict_to_item(v) | |
} | |
elif type(v) is list: | |
resp[k] = [] | |
for i in v: | |
resp[k].append(dict_to_item(i)) | |
return resp | |
elif type(raw) is str: | |
return { | |
'S': raw | |
} | |
elif type(raw) is int: | |
return { | |
'I': str(raw) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment