Skip to content

Instantly share code, notes, and snippets.

@bsesic
Last active April 18, 2024 19:39
Show Gist options
  • Save bsesic/fdebb46928a68d87ae81b6967cd8e1d0 to your computer and use it in GitHub Desktop.
Save bsesic/fdebb46928a68d87ae81b6967cd8e1d0 to your computer and use it in GitHub Desktop.
Generate Hash UUID
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
@bsesic
Copy link
Author

bsesic commented Apr 18, 2024

This function creates a UUID from a hash of a given string.

@bsesic
Copy link
Author

bsesic commented Apr 18, 2024

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