Coverage for langsmith/uuid.py: 0%

12 statements  

« prev     ^ index     » next       coverage.py v7.10.1, created at 2025-12-11 16:15 -0800

1"""Public UUID v7 helpers. 

2 

3These helpers expose utilities for generating UUID v7 identifiers in user code. 

4""" 

5 

6from __future__ import annotations 

7 

8import datetime as _dt 

9import uuid as _uuid 

10 

11from ._internal._uuid import uuid7 as _uuid7 

12 

13 

14def uuid7() -> _uuid.UUID: 

15 """Generate a random UUID v7. 

16 

17 Returns: 

18 uuid.UUID: A random, RFC 9562-compliant UUID v7. 

19 """ 

20 return _uuid7() 

21 

22 

23def uuid7_from_datetime(dt: _dt.datetime) -> _uuid.UUID: 

24 """Generate a UUID v7 from a datetime. 

25 

26 Args: 

27 dt: A timezone-aware datetime. If naive, it is treated as UTC. 

28 

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) 

36 

37 

38__all__ = ["uuid7", "uuid7_from_datetime"]