UUID3 cross compatible in Java and Python

Sometimes, in the world of microservices you want to generate consistent hashes across several languages. I’ve faced a problem of getting the same UUID in Java and Python, and wanted to share how it can be done.

Java

UUID.nameUUIDFromBytes("name".getBytes())
# b068931c-c450-342b-a3f5-b3d276ea4297

Python

class NULL_NAMESPACE:
    bytes = b''

uid.uuid3(NULL_NAMESPACE, "name")
# b068931c-c450-342b-a3f5-b3d276ea4297

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *