# -*- 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)