Created
June 6, 2025 05:10
-
-
Save tjmcewan/87ea361b2f498c8d499c1d8164743639 to your computer and use it in GitHub Desktop.
A method for creating deterministic UUIDs from a batch of existing unique IDs
This file contains hidden or 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
import uuid | |
def id_for_batch(batch_id: uuid.UUID, id: str | int) -> uuid.UUID: | |
return uuid.uuid3(batch_id, str(id)) | |
def main(): | |
batch_id = uuid.uuid4() | |
print(f"Batch ID (1 per batch job): {batch_id}\n\n") | |
local_ids = [ | |
"record_001", | |
"record_002", | |
"txn_abc", | |
234902130948, | |
] | |
print("Local ID \t| Deterministic UUID") | |
print("-" * 55, "\n") | |
for local_id in local_ids: | |
print(f"{local_id} \t| {id_for_batch(batch_id, local_id)}") | |
print("-" * 55, "\n") | |
for local_id in local_ids: | |
print(f"{local_id} \t| {id_for_batch(batch_id, local_id)}") | |
print("-" * 55, "\n") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment