Skip to content

Instantly share code, notes, and snippets.

@tjmcewan
Created June 6, 2025 05:10
Show Gist options
  • Save tjmcewan/87ea361b2f498c8d499c1d8164743639 to your computer and use it in GitHub Desktop.
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
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