uuid.uuid5 and uuid.UUID
uuid.uuid5(namespace, name)
uuid.UUID(hex=None, bytes=None, bytes_le=None, fields=None, int=None, version=None, *, is_safe=SafeUUID.unknown)Build the documented UUID5 for python.org and parse the same value from a hex string.
| Parameter | Description |
|---|---|
namespace, name | A UUID namespace, such as uuid.NAMESPACE_DNS, and the name string. The pair used here is the one from the Python 3.13 documentation. |
hex | A 32-digit hex string, with or without hyphens, used by the UUID constructor. |
Returns: A UUID object. version is 5 for uuid5. hex is the 32-character form without hyphens.
Raises
ValueError— Raised by UUID when the hex string is the wrong length or is not hexadecimal.
- The UUID constructor has several mutually alternative inputs. This example only uses hex. is_safe is shown in the official signature and is not used here.
import uuid
u = uuid.uuid5(uuid.NAMESPACE_DNS, "python.org")
print(u)
print(u.version)
fixed = uuid.UUID("886313e1-3b8a-5372-9b90-0c9aee199e5d")
print(fixed)
print(fixed.hex)
print(u == fixed)Expected output
886313e1-3b8a-5372-9b90-0c9aee199e5d
5
886313e1-3b8a-5372-9b90-0c9aee199e5d
886313e13b8a53729b900c9aee199e5d
TrueRelated: hashlib