Unique Key/ID Generation – Python

A Unique ID -short for Unique Identifier- is a string of characters to uniquely identify a particular entity within a system or context. It provides a unique label or identifier for that entity, distinguishing it from others. Unique keys/Ids are used to database management, networking, and identification systems that matters each data separately.


In Python, uuid is a built-in module that provides functions for generating Universally Unique Identifiers (UUIDs).

UUID can bu used for:

  • Generate Unique Random Id
  • Hashing


This function provides and guarantees the random unique id without compromise with privacy.

also function provides hex without hypens:


uuid.uuid1() function is defined in UUID library and provides generating random ids using MAC address and time component.

What is Mac Address: Media Access Control address, is a unique identifier assigned to network interfaces for communications on a network segment.

Representations of uuid1()

  • bytes : Returns id in form of 16 byte string.
  • int : Returns id in form of 128-bit integer.
  • hex : Returns random id as 32 character hexadecimal string.

Components of uuid1()

  • version : version number of UUID.
  • variant : The variant determining the internal layout of UUID.
ibrahim tunc
ibrahim tunc
Articles: 13

Leave a Reply

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