New in version 2.5.
This module provides immutable UUID objects (the UUID class) and the functions uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5 UUIDs as specified in RFC 4122.
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.
[hex[, bytes[, bytes_le[, fields[, int[, version]]]]]]) |
Create a UUID from either a string of 32 hexadecimal digits, a string of 16 bytes as the bytes argument, a string of 16 bytes in little-endian order as the bytes_le argument, a tuple of six integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version, 8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as the fields argument, or a single 128-bit integer as the int argument. When a string of hex digits is given, curly braces, hyphens, and a URN prefix are all optional. For example, these expressions all yield the same UUID:
UUID('{12345678-1234-5678-1234-567812345678}') UUID('12345678123456781234567812345678') UUID('urn:uuid:12345678-1234-5678-1234-567812345678') UUID(bytes='\x12\x34\x56\x78'*4) UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' + '\x12\x34\x56\x78\x12\x34\x56\x78') UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678)) UUID(int=0x12345678123456781234567812345678)
Exactly one of hex, bytes, bytes_le, fields, or int must be given. The version argument is optional; if given, the resulting UUID will have its variant and version number set according to RFC 4122, overriding bits in the given hex, bytes, bytes_le, fields, or int.
UUID instances have these read-only attributes:
Field | Meaning |
---|---|
time_low | the first 32 bits of the UUID |
time_mid | the next 16 bits of the UUID |
time_hi_version | the next 16 bits of the UUID |
clock_seq_hi_variant | the next 8 bits of the UUID |
clock_seq_low | the next 8 bits of the UUID |
node | the last 48 bits of the UUID |
time | the 60-bit timestamp |
clock_seq | the 14-bit sequence number |
The uuid module defines the following functions:
) |
[node[, clock_seq]]) |
namespace, name) |
) |
namespace, name) |
The uuid module defines the following namespace identifiers for use with uuid3() or uuid5().
The uuid module defines the following constants for the possible values of the variant attribute:
See Also: