Last active
April 18, 2024 19:39
-
-
Save bsesic/fdebb46928a68d87ae81b6967cd8e1d0 to your computer and use it in GitHub Desktop.
Generate Hash UUID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_hash_UUID(name): | |
""" | |
Generate a UUID based on the hashed string | |
Args: name (str): Name of the entity. | |
Returns: str: UUID of the entity. | |
""" | |
# Hash the string using a hashing algorithm (e.g., SHA-256) | |
hashed_string = hashlib.sha256(name.encode()).hexdigest() | |
# Generate a UUID based on the hashed string | |
uuid_from_hash = uuid.uuid5(uuid.NAMESPACE_OID, hashed_string) | |
return uuid_from_hash |
If the string, like a name, stays the same the same UUID will be generated. So there is no need to keep an index file for all the entities and their correspnding UUIDs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function creates a UUID from a hash of a given string.