UUID Python

At some point in your development career you will reach the conclusion that you need universally unique identifiers. For example you want to send out promotion codes and want to ensure that everyone gets a unique code — and do not want that some users could re-use the codes of others by guessing it.

For this comes the uuid module which ships with Python. It implements the versions 1, 3, 4 and 5 of the UUID (https://docs.python.org/3/library/uuid.html) standards. This means you have quite some options to get things rolling.

I am not going into the details of the four implemented standards but I suggest you use uuid.uuid4() if you require some unique and random UUID. The uuid.uuid1() function contains the computer’s network address that is quite problematic privacy-wise. I hope you won’t be angry if I do not provide example results where you can see that it really contains the address (thus the UUIDs generated have very much in common). Just execute the following in your interactive interpreter:

>>> from uuid import uuid1
>>> for i in range(5):
... print(uuid1())
For comparison, let's take a look at uuid4:
>>> from uuid import uuid4
>>> for i in range(5):
... print(uuid4())