Created
October 12, 2017 22:36
-
-
Save azylinski/b61116f74c609cf3b7a4b28d7da65c96 to your computer and use it in GitHub Desktop.
Get uuid from Python dict.
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
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