svix-ksuid

raw JSON →
0.7.0 verified Mon Apr 27 auth: no python

A pure-Python implementation of KSUIDs (K-Sortable Unique IDentifiers). Version 0.7.0 requires Python >= 3.10 and changes KsuidMs precision to 4ms. Library is stable with occasional minor releases.

pip install svix-ksuid
error ModuleNotFoundError: No module named 'svix_ksuid'
cause Incorrect import path; the package is 'ksuid' after installation.
fix
Install the package with 'pip install svix-ksuid' and import from 'ksuid', e.g., 'from ksuid import Ksuid'.
error AttributeError: module 'ksuid' has no attribute 'KsuidMs'
cause KsuidMs was added in v0.6.0; older versions do not have it.
fix
Upgrade to svix-ksuid >=0.6.0: 'pip install --upgrade svix-ksuid'
breaking In v0.7.0, KsuidMs precision changed from 1/256s to 4ms. Existing KsuidMs values generated with older versions will have different timing semantics.
fix Regenerate any KsuidMs values if millisecond precision is critical.
gotcha Do not import from 'svix_ksuid' or any other submodule. The correct import is 'from ksuid import Ksuid'.
fix Use 'from ksuid import Ksuid'.
deprecated Minimum Python version is now 3.10. Older Python versions are unsupported.
fix Upgrade Python to 3.10+.

Basic usage: generate, parse, and work with KSUIDs.

from ksuid import Ksuid

# Generate a new KSUID
ksuid = Ksuid()
print(ksuid)  # e.g., '0oGHV0fW3W7oJ9s8X5K0l1vU9T2F'
print(ksuid.timestamp)  # datetime object

# Parse from string
parsed = Ksuid.from_string('0oGHV0fW3W7oJ9s8X5K0l1vU9T2F')

# Generate a KSUID with millisecond precision
from ksuid import KsuidMs
ms_ksuid = KsuidMs()