Universally Unique Identifiers (UUID)
  • UUID values are 128 bits long, guarantee uniqueness across space and time
  • Used to generate identifiers for documents, hosts, application clients, and other situations where a unique value is necessary
  • Algorithms
  • Using IEEE 802 MAC addresses as a source of uniqueness
  • Using pseudo-random numbers
  • Using well-known strings combined with cryptographic hashing
  • UUID 1
  • generate a UUID for a host, identified by its MAC address
  • each call to uuid1() returns a new value
  • import uuid
    
    u = uuid.uuid1()
    u.version # version
    u.hex # hex
    u.int # int
                
    UUID 3 and 5
  • Create UUID values from names instead of random or time-based values use cryptographic hash values
  • The UUID value for a given name in a namespace is always the same, no matter when or where it is calculated
  • # 'NAMESPACE_DNS','NAMESPACE_OID','NAMESPACE_URL','NAMESPACE_X500',
    hostname = 'www.doughellmann.com'
    
    uuid.uuid3(uuid.NAMESPACE_DNS, hostname) # MD5
    
    uuid.uuid5(uuid.NAMESPACE_DNS, hostname) # SHA-1
                
    UUID 4
  • used as a hash key, a more random sequence of values with more differentiation
  • uuid.uuid4()
                
    Reference
  • PyMOTW