-
-
Save fakabbir/896f4fb66b93d04c6bf5ceb1950c39f7 to your computer and use it in GitHub Desktop.
Coverts a standard Python dictionary to a Boto3 DynamoDB item
This file contains 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