Python implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs
Project description
TypeID Python
A Python implementation of TypeIDs using Python
TypeIDs are a modern, type-safe, globally unique identifier based on the upcoming UUIDv7 standard. They provide a ton of nice properties that make them a great choice as the primary identifiers for your data in a database, APIs, and distributed systems. Read more about TypeIDs in their spec.
This particular implementation provides an pip package that can be used by any Python project.
Installation
-
PyPI:
pip install typeid-python
-
Poetry:
poetry add typeid-python
Usage
-
Create TypeID Instance:
from typeid import TypeID typeid = TypeID() print(typeid.prefix) # "" print(typeid.suffix) # "01h45ytscbebyvny4gc8cr8ma2" (encoded uuid7 instance) typeid = TypeID(prefix="user") print(typeid.prefix) # "user" print(str(typeid)) # "user_01h45ytscbebyvny4gc8cr8ma2"
-
Create TypeID from string:
from typeid import from_string typeid = from_string("user_01h45ytscbebyvny4gc8cr8ma2") print(str(typeid)) # "user_01h45ytscbebyvny4gc8cr8ma2"
-
Create TypeID from uuid7:
from typeid import from_uuid from uuid6 import uuid7 uuid = uuid7() # UUID('01890bf0-846f-7762-8605-5a3abb40e0e5') prefix = "user" typeid = from_uuid(prefix=prefix, suffix=uuid) print(str(typeid)) # "user_01h45z113fexh8c1at7axm1r75"
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
typeid_python-0.1.2.tar.gz
(5.0 kB
view hashes)
Built Distribution
Close
Hashes for typeid_python-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d3041a6ba40653a78b0d1cf5879e6f4a3793f6fa7fb70830e0ffa4d66798bf1 |
|
MD5 | 175229d782f88d6e2a50d830ee009774 |
|
BLAKE2b-256 | dbdd958e2474a8f0db7e56bc8262a09b121710a69a19f8f14fae48f23f22b26b |