All Projects → saresend → KSUID

saresend / KSUID

Licence: MIT License
Sortable UIDs in Python

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to KSUID

duration-humanizer
361000 becomes "6 minutes, 1 second"
Stars: ✭ 61 (-26.51%)
Mutual labels:  datetime
chronos
One library to rule the time
Stars: ✭ 17 (-79.52%)
Mutual labels:  datetime
fuuid
Functional UUIDs for Python.
Stars: ✭ 145 (+74.7%)
Mutual labels:  uid
shamsi date
A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) date and times.
Stars: ✭ 59 (-28.92%)
Mutual labels:  datetime
svelty-picker
Simple date & time picker in svelte
Stars: ✭ 38 (-54.22%)
Mutual labels:  datetime
uef-lib
Useful Erlang Functions Library
Stars: ✭ 14 (-83.13%)
Mutual labels:  datetime
dflex
The sophisticated Drag and Drop library you've been waiting for 🥳
Stars: ✭ 806 (+871.08%)
Mutual labels:  sortable
moment-cache
⏱ Simple utility to cache moment.js results and speed up moment calls.
Stars: ✭ 29 (-65.06%)
Mutual labels:  datetime
imrc-datetime-picker
(Improved) React component datetime picker by momentjs 📆
Stars: ✭ 21 (-74.7%)
Mutual labels:  datetime
PersianTools.Core
Persian Tools for .Net and .Net Core
Stars: ✭ 25 (-69.88%)
Mutual labels:  datetime
zero-drag
Minimal abstraction of DOM drag-and-drop interactions
Stars: ✭ 17 (-79.52%)
Mutual labels:  sortable
FlutterNote
Easy to learn Flutter(Flutter 即学即用,Flutter 速成必备)
Stars: ✭ 22 (-73.49%)
Mutual labels:  datetime
rescript-date
📆 Date manipulation in ReScript.
Stars: ✭ 101 (+21.69%)
Mutual labels:  datetime
dt
Go's missing DateTime package
Stars: ✭ 34 (-59.04%)
Mutual labels:  datetime
date time parser
Parse strings into DateTime, NaiveDateTime, Date, or Time https://hexdocs.pm/date_time_parser
Stars: ✭ 78 (-6.02%)
Mutual labels:  datetime
hs-hourglass
efficient and simpler time API for haskell
Stars: ✭ 43 (-48.19%)
Mutual labels:  datetime
PersianDateRangePicker
Select range of date and time in the Persian
Stars: ✭ 41 (-50.6%)
Mutual labels:  datetime
ember-dayjs-helpers
Ember Template helpers based on day.js
Stars: ✭ 19 (-77.11%)
Mutual labels:  datetime
Date
Fix all needs to date in php
Stars: ✭ 32 (-61.45%)
Mutual labels:  datetime
pendulum-cpp
Pendulum C++ is a simple wrapper around cctz inspired by Pendulum that is beautiful Python library.
Stars: ✭ 13 (-84.34%)
Mutual labels:  datetime

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;
  3. Supports Base62 encoding - can be serialized to Base62 and vice versa

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'

Base62 support

>>> import ksuid
>>> uid = ksuid.ksuid()
>>> print(uid)
>>> '0607ac1e7955e3d6a5da87c8dae2e1825c8ddfc9'
>>> v = uid.toBase62()
>>> print(v)
>>> 'rLIliIsDsLNj1b4tN1T3TZGC1B'

Serialization to bytes support

>>> import ksuid
>>> uid = ksuid.ksuid()
>>> print(uid)
>>> '0607ac7351a48bb5e2f63b68094e465010496ff6'
>>> v = uid.toBytes()
>>> print(v)
>>> b'\x06\x07\xacsQ\xa4\x8b\xb5\xe2\xf6;h\tNFP\x10Io\xf6'

Developing

First of all you need make utility for a little bit comfortable usage.

You can execute make help to view all available commands.

Please, run make to install virtual environment for testing and development.

Supported commands:

  • make - create virtual env and setup dependencies;
  • make tests - run tests;
  • make coverage - run tests with coverage report;
  • make lint - check linting;
  • make flake8 - alias for make lint
  • make clean - remove more or less everything created by make

Credit, where credit is due

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].