Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakabbir/fb4a0f37581e76a34585d8013052fd1c to your computer and use it in GitHub Desktop.
Save fakabbir/fb4a0f37581e76a34585d8013052fd1c to your computer and use it in GitHub Desktop.
Coverts a standard Python dictionary to a Boto3 DynamoDB item
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