Summary of Common Functions of UUID Module in Python
UUID is usually used to generate unique identifiers, such as the ID field of the database, user account number, etc.
The following are some commonly used functions, for more information: https://docs.python.org/3/library/uuid.html.
uuid.uuid1(node=None, clock_seq=None)
Generate a UUID from a host ID, sequence number, and the current time. If node is not given, getnode()
is used to obtain the hardware address. If clock_seq
is given, it is used as the sequence number; otherwise a random 14-bit sequence number is chosen.
uuid.uuid3(namespace, name)
Generate a UUID based on the MD5 hash of a namespace identifier (which is a UUID) and a name (which is a bytes object or a string that will be encoded using UTF-8).
uuid.uuid4()
Generate a random UUID.
uuid.uuid5(namespace, name)
Generate a UUID based on the SHA-1 hash of a namespace identifier (which is a UUID) and a name (which is a bytes object or a string that will be encoded using UTF-8).
Note: You can also output uuid in different forms through
hex
,int
,bytes
and other attributes.
1 | import uuid |
The output is as follows:
1 | uuid_1:ea834337-38b2-11f0-aafd-d444ca5de201 |