Skip to main content

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

Project description

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

ShjZz5Dvr0JyJL00
Shja07nr23XgJk00
Shja1AOUhKufOh00
Shja2CxdQ0AgNa00
Shja3FWSn2wuWu00
Shja4I6kVG860e00

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 unique generated ids on a single machine.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gid-1.0.0.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

gid-1.0.0-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page