"""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) :]