hotpocket/services/packages/common/hotpocket_common/uuid.py
Tomek Wójcik b4338e2769
Some checks failed
CI / Checks (push) Failing after 13m2s
Release v1.0.0
2025-08-20 21:00:50 +02:00

15 lines
407 B
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
import secrets
from uuid6 import UUID
def uuid7_from_timestamp(timestamp: int) -> UUID:
# The code below was shamelessly taken from `uuid6-python` package.
# Copyright (c) 2021 oittaa | MIT License
uuid_int = ((timestamp * 1_000) & 0xFFFFFFFFFFFF) << 80
uuid_int |= secrets.randbits(76)
return UUID(int=uuid_int, version=7)