Home Assistant Unofficial Reference 2024.12.1
ulid.py
Go to the documentation of this file.
1 """Helpers to generate ulids."""
2 
3 from __future__ import annotations
4 
5 from ulid_transform import (
6  bytes_to_ulid,
7  bytes_to_ulid_or_none,
8  ulid_at_time,
9  ulid_hex,
10  ulid_now,
11  ulid_to_bytes,
12  ulid_to_bytes_or_none,
13 )
14 
15 __all__ = [
16  "ulid",
17  "ulid_hex",
18  "ulid_at_time",
19  "ulid_to_bytes",
20  "bytes_to_ulid",
21  "ulid_now",
22  "ulid_to_bytes_or_none",
23  "bytes_to_ulid_or_none",
24 ]
25 
26 
27 def ulid(timestamp: float | None = None) -> str:
28  """Generate a ULID.
29 
30  This ulid should not be used for cryptographically secure
31  operations.
32 
33  01AN4Z07BY 79KA1307SR9X4MV3
34  |----------| |----------------|
35  Timestamp Randomness
36  48bits 80bits
37 
38  This string can be loaded directly with https://github.com/ahawker/ulid
39 
40  import homeassistant.util.ulid as ulid_util
41  import ulid
42  ulid.parse(ulid_util.ulid())
43  """
44  return ulid_now() if timestamp is None else ulid_at_time(timestamp)
str ulid(float|None timestamp=None)
Definition: ulid.py:27