GithubHelp home page GithubHelp logo

kodemore / gid Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 27 KB

Gid is a small library for generating short globally unique, sortable uri safe identifiers.

License: MIT License

Python 100.00%
guid python sortable short url-safe

gid's Introduction

Gid
Release Linting and Tests codecov License: MIT

Gid is a small library for generating short globally unique, sortable uri safe identifiers.

Features

  • Generated ids are sortable
  • Generated ids carry creation time expressed in microseconds
  • Generated ids are globally unique
  • Minimal footprint
  • High performance

Installation

With pip,

pip install gid

or through poetry

poetry add gid

Example ids

ShmX2HaaUB9UQL02 
ShmX2JGvSk4ZyZ13 
ShmX2Ku8mDizRc23 
ShmX2MWQVL5J7022 
ShmX2OCegs4MdP22 
ShmX2Pu2MDVFHa02 
ShmX2RYngGET4Z32 
ShmX2TCM6v701q23 
ShmX2UrBjxNGYM11

Usage

Generating id

from gid import Guid

some_id = Guid()
some_id.timestamp # contains timestamp expressed in milliseconds
str(some_id) # can be cast to a string

Recreating id from string

from gid import Guid
my_id = Guid()

same_id = Guid(str(my_id))

assert same_id == my_id
assert same_id.timestamp == my_id.timestamp

Id structure

Generated identifiers are case-sensitive, which means string functions (like lowercase or uppercase) on generated identifiers may break it because Sbt5LrD9iSAwb300 is not the same value as Sbt5LrD9iSAwB300.

The below diagram represents single identifier's structure, which is 16-character long:

    Sbt5LrD9iSAwb300
    |      |      |
    +- first 7 characters for millisecond timestamp
           |      |
           +- next 7 characters is randomly generated hash
                  |
                  + last two characters to ensure uniqueness of guid in a single millisecond

Within 1 ms there can be (62^2 - 620) unique generated ids on a single machine.

gid's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.