Coverage for langsmith/uuid.py: 0%
12 statements
« prev ^ index » next coverage.py v7.10.1, created at 2025-12-11 16:15 -0800
« prev ^ index » next coverage.py v7.10.1, created at 2025-12-11 16:15 -0800
1"""Public UUID v7 helpers.
3These helpers expose utilities for generating UUID v7 identifiers in user code.
4"""
6from __future__ import annotations
8import datetime as _dt
9import uuid as _uuid
11from ._internal._uuid import uuid7 as _uuid7
14def uuid7() -> _uuid.UUID:
15 """Generate a random UUID v7.
17 Returns:
18 uuid.UUID: A random, RFC 9562-compliant UUID v7.
19 """
20 return _uuid7()
23def uuid7_from_datetime(dt: _dt.datetime) -> _uuid.UUID:
24 """Generate a UUID v7 from a datetime.
26 Args:
27 dt: A timezone-aware datetime. If naive, it is treated as UTC.
29 Returns:
30 uuid.UUID: A UUID v7 whose timestamp corresponds to the provided time.
31 """
32 if dt.tzinfo is None:
33 dt = dt.replace(tzinfo=_dt.timezone.utc)
34 nanoseconds = int(dt.timestamp() * 1_000_000_000)
35 return _uuid7(nanoseconds)
38__all__ = ["uuid7", "uuid7_from_datetime"]