algospaced-dsa / core /__init__.py
iamfebin's picture
feat: zstd zip export, resilient streak date parsing, Python 3.14 modernization, and pathlib migration
a42236e
Raw History Blame Contribute Delete
707 Bytes
"""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) :]