PATH:
usr
/
share
/
doc
/
python3-docs
/
html
/
_sources
/
library
:mod:`uuid` --- UUID objects according to :rfc:`4122` ===================================================== .. module:: uuid :synopsis: UUID objects (universally unique identifiers) according to RFC 4122 .. moduleauthor:: Ka-Ping Yee <ping@zesty.ca> .. sectionauthor:: George Yoshida <quiver@users.sourceforge.net> **Source code:** :source:`Lib/uuid.py` -------------- This module provides immutable :class:`UUID` objects (the :class:`UUID` class) and the functions :func:`uuid1`, :func:`uuid3`, :func:`uuid4`, :func:`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 :func:`uuid1` or :func:`uuid4`. Note that :func:`uuid1` may compromise privacy since it creates a UUID containing the computer's network address. :func:`uuid4` creates a random UUID. .. class:: UUID(hex=None, bytes=None, bytes_le=None, fields=None, int=None, version=None) Create a UUID from either a string of 32 hexadecimal digits, a string of 16 bytes in big-endian order 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=b'\x12\x34\x56\x78'*4) UUID(bytes_le=b'\x78\x56\x34\x12\x34\x12\x78\x56' + b'\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*. Comparison of UUID objects are made by way of comparing their :attr:`UUID.int` attributes. Comparison with a non-UUID object raises a :exc:`TypeError`. ``str(uuid)`` returns a string in the form ``12345678-1234-5678-1234-567812345678`` where the 32 hexadecimal digits represent the UUID. :class:`UUID` instances have these read-only attributes: .. attribute:: UUID.bytes The UUID as a 16-byte string (containing the six integer fields in big-endian byte order). .. attribute:: UUID.bytes_le The UUID as a 16-byte string (with *time_low*, *time_mid*, and *time_hi_version* in little-endian byte order). .. attribute:: UUID.fields A tuple of the six integer fields of the UUID, which are also available as six individual attributes and two derived attributes: +------------------------------+-------------------------------+ | Field | Meaning | +==============================+===============================+ | :attr:`time_low` | the first 32 bits of the UUID | +------------------------------+-------------------------------+ | :attr:`time_mid` | the next 16 bits of the UUID | +------------------------------+-------------------------------+ | :attr:`time_hi_version` | the next 16 bits of the UUID | +------------------------------+-------------------------------+ | :attr:`clock_seq_hi_variant` | the next 8 bits of the UUID | +------------------------------+-------------------------------+ | :attr:`clock_seq_low` | the next 8 bits of the UUID | +------------------------------+-------------------------------+ | :attr:`node` | the last 48 bits of the UUID | +------------------------------+-------------------------------+ | :attr:`time` | the 60-bit timestamp | +------------------------------+-------------------------------+ | :attr:`clock_seq` | the 14-bit sequence number | +------------------------------+-------------------------------+ .. attribute:: UUID.hex The UUID as a 32-character hexadecimal string. .. attribute:: UUID.int The UUID as a 128-bit integer. .. attribute:: UUID.urn The UUID as a URN as specified in :rfc:`4122`. .. attribute:: UUID.variant The UUID variant, which determines the internal layout of the UUID. This will be one of the constants :const:`RESERVED_NCS`, :const:`RFC_4122`, :const:`RESERVED_MICROSOFT`, or :const:`RESERVED_FUTURE`. .. attribute:: UUID.version The UUID version number (1 through 5, meaningful only when the variant is :const:`RFC_4122`). The :mod:`uuid` module defines the following functions: .. function:: getnode() Get the hardware address as a 48-bit positive integer. The first time this runs, it may launch a separate program, which could be quite slow. If all attempts to obtain the hardware address fail, we choose a random 48-bit number with its eighth bit set to 1 as recommended in :rfc:`4122`. "Hardware address" means the MAC address of a network interface, and on a machine with multiple network interfaces the MAC address of any one of them may be returned. .. index:: single: getnode .. function:: uuid1(node=None, clock_seq=None) Generate a UUID from a host ID, sequence number, and the current time. If *node* is not given, :func:`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. .. index:: single: uuid1 .. function:: 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 string). .. index:: single: uuid3 .. function:: uuid4() Generate a random UUID. .. index:: single: uuid4 .. function:: 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 string). .. index:: single: uuid5 The :mod:`uuid` module defines the following namespace identifiers for use with :func:`uuid3` or :func:`uuid5`. .. data:: NAMESPACE_DNS When this namespace is specified, the *name* string is a fully-qualified domain name. .. data:: NAMESPACE_URL When this namespace is specified, the *name* string is a URL. .. data:: NAMESPACE_OID When this namespace is specified, the *name* string is an ISO OID. .. data:: NAMESPACE_X500 When this namespace is specified, the *name* string is an X.500 DN in DER or a text output format. The :mod:`uuid` module defines the following constants for the possible values of the :attr:`variant` attribute: .. data:: RESERVED_NCS Reserved for NCS compatibility. .. data:: RFC_4122 Specifies the UUID layout given in :rfc:`4122`. .. data:: RESERVED_MICROSOFT Reserved for Microsoft compatibility. .. data:: RESERVED_FUTURE Reserved for future definition. .. seealso:: :rfc:`4122` - A Universally Unique IDentifier (UUID) URN Namespace This specification defines a Uniform Resource Name namespace for UUIDs, the internal format of UUIDs, and methods of generating UUIDs. .. _uuid-example: Example ------- Here are some examples of typical usage of the :mod:`uuid` module:: >>> import uuid >>> # make a UUID based on the host ID and current time >>> uuid.uuid1() 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() 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 string >>> uuid.UUID(bytes=x.bytes) UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
[+]
..
[-] crypt.rst.txt
[edit]
[-] logging.handlers.rst.txt
[edit]
[-] __main__.rst.txt
[edit]
[-] pty.rst.txt
[edit]
[-] email.rst.txt
[edit]
[-] traceback.rst.txt
[edit]
[-] fileinput.rst.txt
[edit]
[-] xml.sax.reader.rst.txt
[edit]
[-] curses.rst.txt
[edit]
[-] copy.rst.txt
[edit]
[-] aifc.rst.txt
[edit]
[-] xmlrpc.client.rst.txt
[edit]
[-] pydoc.rst.txt
[edit]
[-] asyncio-eventloops.rst.txt
[edit]
[-] uuid.rst.txt
[edit]
[-] functional.rst.txt
[edit]
[-] posix.rst.txt
[edit]
[-] hashlib.rst.txt
[edit]
[-] cmd.rst.txt
[edit]
[-] nntplib.rst.txt
[edit]
[-] python.rst.txt
[edit]
[-] types.rst.txt
[edit]
[-] exceptions.rst.txt
[edit]
[-] tracemalloc.rst.txt
[edit]
[-] othergui.rst.txt
[edit]
[-] xml.dom.pulldom.rst.txt
[edit]
[-] inspect.rst.txt
[edit]
[-] asyncio-stream.rst.txt
[edit]
[-] i18n.rst.txt
[edit]
[-] concurrent.rst.txt
[edit]
[-] imghdr.rst.txt
[edit]
[-] spwd.rst.txt
[edit]
[-] os.path.rst.txt
[edit]
[-] email.message.rst.txt
[edit]
[-] random.rst.txt
[edit]
[-] fileformats.rst.txt
[edit]
[-] faulthandler.rst.txt
[edit]
[-] parser.rst.txt
[edit]
[-] stat.rst.txt
[edit]
[-] code.rst.txt
[edit]
[-] email.headerregistry.rst.txt
[edit]
[-] timeit.rst.txt
[edit]
[-] optparse.rst.txt
[edit]
[-] smtplib.rst.txt
[edit]
[-] filesys.rst.txt
[edit]
[-] email.mime.rst.txt
[edit]
[-] itertools.rst.txt
[edit]
[-] sys.rst.txt
[edit]
[-] bdb.rst.txt
[edit]
[-] stringprep.rst.txt
[edit]
[-] asyncio-subprocess.rst.txt
[edit]
[-] decimal.rst.txt
[edit]
[-] unicodedata.rst.txt
[edit]
[-] intro.rst.txt
[edit]
[-] constants.rst.txt
[edit]
[-] xmlrpc.rst.txt
[edit]
[-] grp.rst.txt
[edit]
[-] pickle.rst.txt
[edit]
[-] mmap.rst.txt
[edit]
[-] debug.rst.txt
[edit]
[-] unittest.mock-examples.rst.txt
[edit]
[-] undoc.rst.txt
[edit]
[-] functools.rst.txt
[edit]
[-] ssl.rst.txt
[edit]
[-] locale.rst.txt
[edit]
[-] secrets.rst.txt
[edit]
[-] pprint.rst.txt
[edit]
[-] email.header.rst.txt
[edit]
[-] email.contentmanager.rst.txt
[edit]
[-] _thread.rst.txt
[edit]
[-] errno.rst.txt
[edit]
[-] sunau.rst.txt
[edit]
[-] syslog.rst.txt
[edit]
[-] tkinter.ttk.rst.txt
[edit]
[-] distribution.rst.txt
[edit]
[-] pdb.rst.txt
[edit]
[-] distutils.rst.txt
[edit]
[-] dummy_threading.rst.txt
[edit]
[-] text.rst.txt
[edit]
[-] socketserver.rst.txt
[edit]
[-] _dummy_thread.rst.txt
[edit]
[-] persistence.rst.txt
[edit]
[-] asyncio-eventloop.rst.txt
[edit]
[-] collections.abc.rst.txt
[edit]
[-] fnmatch.rst.txt
[edit]
[-] quopri.rst.txt
[edit]
[-] http.server.rst.txt
[edit]
[-] keyword.rst.txt
[edit]
[-] xml.dom.rst.txt
[edit]
[-] cgi.rst.txt
[edit]
[-] heapq.rst.txt
[edit]
[-] email.iterators.rst.txt
[edit]
[-] io.rst.txt
[edit]
[-] curses.panel.rst.txt
[edit]
[-] winreg.rst.txt
[edit]
[-] urllib.parse.rst.txt
[edit]
[-] unix.rst.txt
[edit]
[-] getpass.rst.txt
[edit]
[-] sched.rst.txt
[edit]
[-] socket.rst.txt
[edit]
[-] pipes.rst.txt
[edit]
[-] email.compat32-message.rst.txt
[edit]
[-] asyncio-sync.rst.txt
[edit]
[-] modulefinder.rst.txt
[edit]
[-] html.entities.rst.txt
[edit]
[-] ctypes.rst.txt
[edit]
[-] pyexpat.rst.txt
[edit]
[-] pyclbr.rst.txt
[edit]
[-] html.rst.txt
[edit]
[-] test.rst.txt
[edit]
[-] markup.rst.txt
[edit]
[-] doctest.rst.txt
[edit]
[-] csv.rst.txt
[edit]
[-] colorsys.rst.txt
[edit]
[-] xml.sax.rst.txt
[edit]
[-] zlib.rst.txt
[edit]
[-] subprocess.rst.txt
[edit]
[-] base64.rst.txt
[edit]
[-] platform.rst.txt
[edit]
[-] binascii.rst.txt
[edit]
[-] http.rst.txt
[edit]
[-] nis.rst.txt
[edit]
[-] statistics.rst.txt
[edit]
[-] sqlite3.rst.txt
[edit]
[-] json.rst.txt
[edit]
[-] gzip.rst.txt
[edit]
[-] netdata.rst.txt
[edit]
[-] pkgutil.rst.txt
[edit]
[-] linecache.rst.txt
[edit]
[-] cgitb.rst.txt
[edit]
[-] archiving.rst.txt
[edit]
[-] argparse.rst.txt
[edit]
[-] wsgiref.rst.txt
[edit]
[-] tokenize.rst.txt
[edit]
[-] mm.rst.txt
[edit]
[-] telnetlib.rst.txt
[edit]
[-] ossaudiodev.rst.txt
[edit]
[-] tk.rst.txt
[edit]
[-] string.rst.txt
[edit]
[-] misc.rst.txt
[edit]
[-] marshal.rst.txt
[edit]
[-] email.encoders.rst.txt
[edit]
[-] array.rst.txt
[edit]
[-] queue.rst.txt
[edit]
[-] copyreg.rst.txt
[edit]
[-] atexit.rst.txt
[edit]
[-] signal.rst.txt
[edit]
[-] collections.rst.txt
[edit]
[-] tkinter.scrolledtext.rst.txt
[edit]
[-] tempfile.rst.txt
[edit]
[-] codeop.rst.txt
[edit]
[-] threading.rst.txt
[edit]
[-] enum.rst.txt
[edit]
[-] imp.rst.txt
[edit]
[-] crypto.rst.txt
[edit]
[-] bisect.rst.txt
[edit]
[-] dbm.rst.txt
[edit]
[-] formatter.rst.txt
[edit]
[-] language.rst.txt
[edit]
[-] trace.rst.txt
[edit]
[-] tkinter.tix.rst.txt
[edit]
[-] smtpd.rst.txt
[edit]
[-] asyncio-task.rst.txt
[edit]
[-] abc.rst.txt
[edit]
[-] gettext.rst.txt
[edit]
[-] concurrency.rst.txt
[edit]
[-] allos.rst.txt
[edit]
[-] xml.sax.utils.rst.txt
[edit]
[-] tty.rst.txt
[edit]
[-] mailcap.rst.txt
[edit]
[-] msvcrt.rst.txt
[edit]
[-] reprlib.rst.txt
[edit]
[-] development.rst.txt
[edit]
[-] contextlib.rst.txt
[edit]
[-] configparser.rst.txt
[edit]
[-] symbol.rst.txt
[edit]
[-] shlex.rst.txt
[edit]
[-] tabnanny.rst.txt
[edit]
[-] asyncio-dev.rst.txt
[edit]
[-] py_compile.rst.txt
[edit]
[-] uu.rst.txt
[edit]
[-] logging.rst.txt
[edit]
[-] runpy.rst.txt
[edit]
[-] pathlib.rst.txt
[edit]
[-] os.rst.txt
[edit]
[-] urllib.request.rst.txt
[edit]
[-] html.parser.rst.txt
[edit]
[-] bz2.rst.txt
[edit]
[-] binhex.rst.txt
[edit]
[-] time.rst.txt
[edit]
[-] zipapp.rst.txt
[edit]
[-] fcntl.rst.txt
[edit]
[-] tkinter.rst.txt
[edit]
[-] glob.rst.txt
[edit]
[-] email.policy.rst.txt
[edit]
[-] pwd.rst.txt
[edit]
[-] numeric.rst.txt
[edit]
[-] winsound.rst.txt
[edit]
[-] urllib.robotparser.rst.txt
[edit]
[-] selectors.rst.txt
[edit]
[-] xdrlib.rst.txt
[edit]
[-] webbrowser.rst.txt
[edit]
[-] zipfile.rst.txt
[edit]
[-] ipc.rst.txt
[edit]
[-] mailbox.rst.txt
[edit]
[-] plistlib.rst.txt
[edit]
[-] getopt.rst.txt
[edit]
[-] concurrent.futures.rst.txt
[edit]
[-] symtable.rst.txt
[edit]
[-] rlcompleter.rst.txt
[edit]
[-] __future__.rst.txt
[edit]
[-] asynchat.rst.txt
[edit]
[-] audioop.rst.txt
[edit]
[-] compileall.rst.txt
[edit]
[-] unittest.mock.rst.txt
[edit]
[-] dis.rst.txt
[edit]
[-] index.rst.txt
[edit]
[-] logging.config.rst.txt
[edit]
[-] gc.rst.txt
[edit]
[-] shutil.rst.txt
[edit]
[-] sndhdr.rst.txt
[edit]
[-] ipaddress.rst.txt
[edit]
[-] asyncio-queue.rst.txt
[edit]
[-] curses.ascii.rst.txt
[edit]
[-] builtins.rst.txt
[edit]
[-] calendar.rst.txt
[edit]
[-] sysconfig.rst.txt
[edit]
[-] token.rst.txt
[edit]
[-] xml.dom.minidom.rst.txt
[edit]
[-] textwrap.rst.txt
[edit]
[-] importlib.rst.txt
[edit]
[-] fpectl.rst.txt
[edit]
[-] mimetypes.rst.txt
[edit]
[-] netrc.rst.txt
[edit]
[-] fractions.rst.txt
[edit]
[-] select.rst.txt
[edit]
[-] lzma.rst.txt
[edit]
[-] math.rst.txt
[edit]
[-] frameworks.rst.txt
[edit]
[-] ftplib.rst.txt
[edit]
[-] macpath.rst.txt
[edit]
[-] numbers.rst.txt
[edit]
[-] xml.etree.elementtree.rst.txt
[edit]
[-] pickletools.rst.txt
[edit]
[-] asyncore.rst.txt
[edit]
[-] warnings.rst.txt
[edit]
[-] resource.rst.txt
[edit]
[-] unittest.rst.txt
[edit]
[-] datetime.rst.txt
[edit]
[-] asyncio-protocol.rst.txt
[edit]
[-] urllib.rst.txt
[edit]
[-] superseded.rst.txt
[edit]
[-] email.generator.rst.txt
[edit]
[-] ensurepip.rst.txt
[edit]
[-] ast.rst.txt
[edit]
[-] modules.rst.txt
[edit]
[-] venv.rst.txt
[edit]
[-] internet.rst.txt
[edit]
[-] chunk.rst.txt
[edit]
[-] asyncio.rst.txt
[edit]
[-] turtle.rst.txt
[edit]
[-] struct.rst.txt
[edit]
[-] profile.rst.txt
[edit]
[-] urllib.error.rst.txt
[edit]
[-] http.cookiejar.rst.txt
[edit]
[-] tarfile.rst.txt
[edit]
[-] http.cookies.rst.txt
[edit]
[-] multiprocessing.rst.txt
[edit]
[-] msilib.rst.txt
[edit]
[-] xmlrpc.server.rst.txt
[edit]
[-] termios.rst.txt
[edit]
[-] 2to3.rst.txt
[edit]
[-] windows.rst.txt
[edit]
[-] email.examples.rst.txt
[edit]
[-] readline.rst.txt
[edit]
[-] binary.rst.txt
[edit]
[-] shelve.rst.txt
[edit]
[-] re.rst.txt
[edit]
[-] xml.sax.handler.rst.txt
[edit]
[-] hmac.rst.txt
[edit]
[-] datatypes.rst.txt
[edit]
[-] typing.rst.txt
[edit]
[-] custominterp.rst.txt
[edit]
[-] email.charset.rst.txt
[edit]
[-] email.util.rst.txt
[edit]
[-] zipimport.rst.txt
[edit]
[-] cmath.rst.txt
[edit]
[-] idle.rst.txt
[edit]
[-] operator.rst.txt
[edit]
[-] site.rst.txt
[edit]
[-] email.parser.rst.txt
[edit]
[-] functions.rst.txt
[edit]
[-] poplib.rst.txt
[edit]
[-] filecmp.rst.txt
[edit]
[-] codecs.rst.txt
[edit]
[-] imaplib.rst.txt
[edit]
[-] stdtypes.rst.txt
[edit]
[-] difflib.rst.txt
[edit]
[-] weakref.rst.txt
[edit]
[-] http.client.rst.txt
[edit]
[-] email.errors.rst.txt
[edit]
[-] xml.rst.txt
[edit]
[-] wave.rst.txt
[edit]