Python Glossary Русский

all Python 3uuidfunction

uuid.uuid5()

generating UUIDs

A version 5 UUID — deterministic: SHA-1 of a namespace and a name. The same name always gives the same UUID.

Syntax

uuid.uuid5(namespace, name)

This is not a random identifier: anyone who knows the name computes the same UUID, so never derive secrets from it. The namespace is a UUID too: NAMESPACE_DNS, NAMESPACE_URL or your own, created once and hard-coded as a constant; changing it changes every value ever issued. A string is encoded as UTF-8, bytes are used as is.

Examples

import uuid
u = uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
print(u)  # → 886313e1-3b8a-5372-9b90-0c9aee199e5d
# Python 3.12+
import uuid
u = uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
print(u == uuid.uuid5(uuid.NAMESPACE_DNS, b'python.org'))  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy