PyDocs

Internet Protocols and Support

uuid

UUID objects (universally unique identifiers) according to RFC 4122/9562.

This module provides immutable UUID objects (class UUID) and functions for
generating UUIDs corresponding to a specific UUID version as specified in
RFC 4122/9562, e.g., uuid1() for UUID version 1, uuid3() for UUID version 3,
and so on.

Note that UUID version 2 is deliberately omitted as it is outside the scope
of the RFC.

If all you want is a unique ID, you should probably call uuid1() or uuid4().
Note that uuid1() may compromise privacy since it creates a UUID containing
the computer's network address.  uuid4() creates a random UUID.

Typical usage:

    >>> import uuid

    # make a UUID based on the host ID and current time
    >>> uuid.uuid1()    # doctest: +SKIP
    UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')

    # make a UUID using an MD5 hash of a namespace UUID and a name
    >>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
    UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')

    # make a random UUID
    >>> uuid.uuid4()    # doctest: +SKIP
    UUID('16fd2706-8baf-433b-82eb-8c7fada847da')

    # make a UUID using a SHA-1 hash of a namespace UUID and a name
    >>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
    UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')

    # make a UUID from a string of hex digits (braces and hyphens ignored)
    >>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}')

    # convert a UUID to a string of hex digits in standard form
    >>> str(x)
    '00010203-0405-0607-0809-0a0b0c0d0e0f'

    # get the raw 16 bytes of the UUID
    >>> x.bytes
    b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'

    # make a UUID from a 16-byte bytes object
    >>> uuid.UUID(bytes=x.bytes)
    UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')

    # get the Nil UUID
    >>> uuid.NIL
    UUID('00000000-0000-0000-0000-000000000000')

    # get the Max UUID
    >>> uuid.MAX
    UUID('ffffffff-ffff-ffff-ffff-ffffffffffff')
Symbols in uuid

g

getnode
Get the hardware address as a 48-bit positive integer.

m

MAX
A special form of UUID that is specified to have all 128 bits set to one according to RFC 9562, §5.10.

n

NAMESPACE_DNS
When this namespace is specified, the name string is a fully qualified domain name.
NAMESPACE_OID
When this namespace is specified, the name string is an ISO OID.
NAMESPACE_URL
When this namespace is specified, the name string is a URL.
NAMESPACE_X500
When this namespace is specified, the name string is an X.500 DN in DER or a text output format.
NIL
A special form of UUID that is specified to have all 128 bits set to zero according to RFC 9562, §5.9.

r

RESERVED_FUTURE
Reserved for future definition.
RESERVED_MICROSOFT
Reserved for Microsoft compatibility.
RESERVED_NCS
Reserved for NCS compatibility.
RFC_4122
Specifies the UUID layout given in RFC 4122.

s

SafeUUID
An enumeration.

u

UUID
Instances of the UUID class represent UUIDs as specified in RFC 4122.
uuid1
Generate a UUID from a host ID, sequence number, and the current time.
uuid3
Generate a UUID from the MD5 hash of a namespace UUID and a name.
uuid4
Generate a random UUID.
uuid5
Generate a UUID from the SHA-1 hash of a namespace UUID and a name.
uuid6
Similar to :func:`uuid1` but where fields are ordered differently for improved DB locality.
uuid7
Generate a UUID from a Unix timestamp in milliseconds and random bits.
uuid8
Generate a UUID from three custom blocks.