https://github.com/kodemore/gid
Gid is a small library for generating short globally unique, sortable uri safe identifiers.
https://github.com/kodemore/gid
guid python short sortable url-safe
Last synced: 5 months ago
JSON representation
Gid is a small library for generating short globally unique, sortable uri safe identifiers.
- Host: GitHub
- URL: https://github.com/kodemore/gid
- Owner: kodemore
- License: mit
- Created: 2021-09-01T04:25:28.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-01T17:41:02.000Z (over 3 years ago)
- Last Synced: 2024-11-29T09:43:39.659Z (5 months ago)
- Topics: guid, python, short, sortable, url-safe
- Language: Python
- Homepage:
- Size: 26.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gid
[](https://github.com/kodemore/gid/actions/workflows/release.yml) [](https://github.com/kodemore/gid/actions/workflows/main.yaml) [](https://codecov.io/gh/kodemore/gid) [](https://opensource.org/licenses/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,
```shell
pip install gid
```
or through poetry
```shell
poetry add gid
```## Example ids
```
ShmX2HaaUB9UQL02
ShmX2JGvSk4ZyZ13
ShmX2Ku8mDizRc23
ShmX2MWQVL5J7022
ShmX2OCegs4MdP22
ShmX2Pu2MDVFHa02
ShmX2RYngGET4Z32
ShmX2TCM6v701q23
ShmX2UrBjxNGYM11
```# Usage
## Generating id
```python
from gid import Guidsome_id = Guid()
some_id.timestamp # contains timestamp expressed in milliseconds
str(some_id) # can be cast to a string
```## Recreating id from string
```python
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.