File size: 707 Bytes
8800c81
a42236e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Core shared utilities and dependencies for AlgoSpaced."""

import uuid


def uuid_str() -> str:
    """Generates a UUID string using Python 3.14's native uuid.uuid7() (RFC 9562).

    Falls back to uuid.uuid4() if running in pre-3.14 environments.
    """
    uuid_func = getattr(uuid, "uuid7", uuid.uuid4)
    return str(uuid_func())


def uuid_hex_short(length: int = 8) -> str:
    """Generates a short hex identifier from a UUID (UUIDv7 in Python 3.14+, UUIDv4 fallback).

    Extracts from the random suffix to prevent collisions across sub-minute calls.
    """
    if length <= 0:
        return ""
    uuid_func = getattr(uuid, "uuid7", uuid.uuid4)
    return uuid_func().hex[-min(length, 32) :]