hotpocket/services/packages/common/hotpocket_common/uuid.py
Tomek Wójcik d909391ee6
Some checks failed
CI / Checks (push) Has been cancelled
Release v1.0.0rc1
2025-08-18 07:09:27 +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)