Skip to content

lepy/KSUID

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

KSUID

What is a ksuid?

A ksuid is a K sorted UID. In other words, a KSUID also stores a date component, so that ksuids can be approximately sorted based on the time they were created.

Quick overview

A ksuid is composed of two components: the date time, which is stored as the first four bytes of the uid, along with a randomly generated payload of 16, for a total of 20 bytes.

A few advantages

  1. The potential number of IDs available is greater than even that of UUID4 (which accepts 122 bits). KSUIDs are about 64 times larger than that. Coupled with the timestamp, the likelihood of getting 2 identical Ksuids is exceedingly low

  2. Enables sorting of UIDs in a sensible fashion, based on their timestamp.

Installation

The ksuid library can be installed via pip: pip install ksuid

Note: currently only tested for Python 3.x

Sample Usage:

>>> from ksuid import ksuid
>>> x = ksuid()
>>> print(x) 
>>> '05cbd3454355fe1e1f11c85bb2c1e3e2f7c93525 '
>>> x.getTimestamp()
>>> 1497243973
>>> x.getDatetime() 
>>> datetime.date(2017, 6, 11)
>>> x 
>>> <ksuid.ksuid object at 0x100784a90> 
>>> x.bytes()
>>> b'\x05\xcb\xd7\xd0\xc6\xcb\x98i\xeb\xa0}\xfa\x0f\x87\xf1\xf1\xe8\xa1\x83\x9e'

Credit, where credit is due

This library is largely inspired by the go version, found here: https://github.com/segmentio/ksuid

About

Sortable UIDs in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%