Python UUID

>>> import uuid

>>> # make a UUID based on the host ID and current time
>>> uuid.uuid1()

>>> # make a UUID using an MD5 hash of a namespace UUID and a name
>>> uuid.uuid3(uuid.NAMESPACE_DNS, '')

>>> # make a random UUID
>>> uuid.uuid4()

>>> # make a UUID using a SHA-1 hash of a namespace UUID and a name
>>> uuid.uuid5(uuid.NAMESPACE_DNS, '')

>>> # 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)

>>> # get the raw 16 bytes of the UUID
>>> x.bytes

>>> # make a UUID from a 16-byte string
>>> uuid.UUID(bytes=x.bytes)

References :

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.