
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Generating hash ids using uuid3() and uuid5() in Python
The universally unique identifier is a 32 bit hexadecimal number that can guarantee a unique value in a given namespace. This helps in tracking down objects created by a program or where ever python needs to handle object or data that needs large value of identifier. The UUID class defines functions that can create these values.
Syntax
uuid3(namespace, string) uuid3 usesMD5 hash value to create the identifier. Uuid5(namespace, string) Uuid5 uses SHA-1 hash value to create the identifier. The namespace can be – NAMESPACE_DNS : Used when name string is fully qualified domain name. NAMESPACE_URL : Used when name string is a URL.
In the below example we see that we can choose an initial string which can be further used to create the uuids..
Example
import uuid # A given string str1 = "www.tutorialspoint.com" str2 = "http://www.Tutorialspoint.com" print("Using uuid3, the generated ID is :\n", uuid.uuid3(uuid.NAMESPACE_URL, str1)) print("Using uuid3, the generated ID is :\n", uuid.uuid3(uuid.NAMESPACE_DNS, str2)) print("Using uuid5, the generated ID is :\n ", uuid.uuid5(uuid.NAMESPACE_URL, str1)) print("Using uuid5, the generated ID is :\n", uuid.uuid5(uuid.NAMESPACE_DNS, str2))
Running the above code gives us the following result:
Output
Using uuid3, the generated ID is : e5051d13-d1a5-381a-bc21-5017b275a7f2 Using uuid3, the generated ID is : de365612-734a-38e3-abc4-6e3ffc7d61db Using uuid5, the generated ID is : a064f94e-5ff6-51e4-88e2-e2163a79abce Using uuid5, the generated ID is : b9761e0a-0ef3-5fd3-9ec4-86b6e073e61b
- Related Articles
- Generating an SHA-256 Hash From Command Line
- MD5 hash encoding using Python?
- Generating a SHA-256 hash from the Linux command line
- Generating Random id's using UUID in Python
- Keyed Hash for Message Authentication using Python
- Generating random Id’s in Python
- How to generate a 24bit hash using Python?
- How to Find Hash of File using Python?
- Generating random number list in Python
- Hash Functions and Hash Tables
- Generating Random String Using PHP
- Generating random strings until a given string is generated using Python
- Compare two tables and return missing ids using MySQL LEFT OUTER JOIN
- Creating a hash table using Javascript
- Lock & Key problem using Hash-map

Advertisements