Skip to content

Instantly share code, notes, and snippets.

@azylinski
Created October 12, 2017 22:36
Show Gist options
  • Save azylinski/b61116f74c609cf3b7a4b28d7da65c96 to your computer and use it in GitHub Desktop.
Save azylinski/b61116f74c609cf3b7a4b28d7da65c96 to your computer and use it in GitHub Desktop.
Get uuid from Python dict.
from json import JSONEncoder, dumps
from datetime import date, datetime
from uuid import NAMESPACE_DNS, uuid3
class DateTimeEncoder(JSONEncoder):
def default(self, obj):
if isinstance(obj, (date, datetime)):
return obj.isoformat()
return JSONEncoder.default(self, obj)
def dict_to_uuid(data):
return str(uuid3(NAMESPACE_DNS, dumps(data, cls=DateTimeEncoder, sort_keys=True)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment