Difference between versions of the uuid Python package

Asked

Viewed 89 times

0

I need to create unique Ids and for this I will use the package uuid. However, when it came time to import I was wondering which version to use:

inserir a descrição da imagem aqui

Is there a reasonable reason to have so many different versions of this same package (5!) in the standard Python library?

  • They are not random Python implementations, they are in fact all standard UUID specifications. Each uses different input parameters.

1 answer

2


According to the Python documentation if you want to create unique Ids you should probably use uuid1 or the uuid4 taking into account that the first option can compromise privacy by creating a UUID containing the host’s MAC address, while the second creates a UUID random.

  • uuid1: Generate from the host machine’s MAC address plus a sentence containing the sequence number (if you cannot get the sequence, a 14-bit number is generated randomly) and the current time
  • uuid2: Generates a random UUID.

Why not use uuid3 or uuid5?

To create unique Ids it is not advisable to use the uuid3 and the uuid5 because the first is based on the MD5 hash of a namespace identifier (which is a UUID) and a name (which is a string). The second one does the same but uses the SHA-1 hash.

Note: The nome used in the generation of uuid3 and uuid5 may be a domain, a URL, an OID (Identification Object) or a X.500DN or an output text format.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.