Python - Why use anything other than uuid4() for unique strings? Python - Why use anything other than uuid4() for unique strings? python python

Python - Why use anything other than uuid4() for unique strings?


Using a hash to uniquely identify a resource allows you to generate a 'unique' reference from the object. For instance, Git uses SHA hashing to make a unique hash that represents the exact changeset of a single a commit. Since hashing is deterministic, you'll get the same hash for the same file every time.

Two people across the world could make the same change to the same repo independently, and Git would know they made the same change. UUID v1, v2, and v4 can't support that since they have no relation to the file or the file's contents.


Well, sometimes you want collisions. If someone uploads the same exact image twice, maybe you'd rather tell them it's a duplicate rather than just make another copy with a new name.


One possible reason is that you want the unique string to be human-readable. UUIDs just aren't easy to read.