image

the sleepy snake

index :: uuid

Module uuid

Python module for generating UUIDs

the UUIDs generated should be compatible to UUID's as specified in RFC 4122. You can create time based, random, sh5 and sha1 based UUIDS through the module. Time based UUIDS generated consist of a timestamp and a randomly generated 47 bit number. No ip or hardware adress is mixed in in time based UUIDs, so anonymity of the user is guaranteed by the cost of a somewhat higher risk of duplicates.

Requirements: at least Python 2.3 (if you don't mind some FutureWarnings)

Additional reading:

  • If you have no idea what an UUID is good for see whats an UUID anyway?
  • some more advanced sniplets (site removed. Too troublesome)
  • Issues

uuid classes:

UuidGenclass to create md5, sha1, random and time based UUIDs

uuid functions:

clean(uuid)removes decoration from a UUID
format_mac_address(mac_addr)formats an integer MAC address as string
get_mac_address(uuid)returns the MAC address of a UUID
get_time(uuid)returns the time portion of a UUID
get_variant(uuid)returns the variant of a UUID
get_version(uuid)returns the version of a UUID
uuid_md5(nsuuid, name)convenience wrapper for UuidGen.uuid_md5()
uuid_sha1(nsuuid, name)convenience wrapper for UuidGen.uuid_sha1()
uuid_random()convenience wrapper for UuidGen.uuid_random()
uuid_time()convenience wrapper for UuidGen.uuid_time()

uuid constants:

VARIANT_UNKNOWNunknown variant
VARIANT_NCSreserved for NCS backward compatibility
VARIANT_RFC4122RFC4122 compatible (produced by this module)
VARIANT_MSReserved for Microsoft backward compatibility
VARIANT_FUTUREReserved for future definition


VERSION_UNKNOWNunknown version
VERSION_TIMEtime based UUID
VERSION_DCEDCE Security version
VERSION_MD5name based UUID with MD5 hashing
VERSION_RANDOMrandomly generated UUID
VERSION_SHA1name based UUID with SHA1 hashing


NAMESPACE_DNSDNS namespace UUID
NAMESPACE_URLURL namespace UUID
NAMESPACE_OIDOID namespace UUID
NAMESPACE_X500X500 namespace UUID


UUID_NILempty UUID

Commandline usage

The module may aswell be used from commandline

enter: /path/to/python /path/to/uuid.py -h

on a commandline prompt to get online help