TypeID Python
typeid-python is a Python implementation of TypeIDs, offering type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs. It is actively maintained with frequent releases, focusing on performance, robustness, and developer experience.
Warnings
- breaking Python 3.8 and 3.9 support was dropped. The library now requires Python 3.10 or newer.
- breaking The prefix validation was updated in v0.3.0 to adhere strictly to the TypeID specification regex (`[a-z]{0,63}`). Prefixes that were previously accepted but did not conform will now raise an error.
- gotcha Starting from v0.3.5, the library introduced optional Rust acceleration, which became standard in v0.3.7 for improved performance in base32 encoding/decoding and UUIDv7 generation. While a pure-Python fallback exists, users might experience performance differences on platforms where native wheels aren't available or if the Rust extension fails to build.
- gotcha Prior to v0.3.9, there was an issue with Pydantic JSON schema generation for FastAPI/OpenAPI, leading to incorrect schema definitions. This was fixed in v0.3.9.
Install
-
pip install typeid-python
Imports
- TypeID
from typeid import TypeID
Quickstart
from typeid import TypeID
# Generate a new TypeID with a prefix (uses a new UUIDv7 internally)
user_id = TypeID("user")
print(f"Generated TypeID: {user_id}")
print(f"Prefix: {user_id.prefix}")
print(f"UUID: {user_id.uuid}") # Raw UUID object
# Get the string representation
user_id_str = str(user_id)
print(f"String representation: {user_id_str}")
# Parse a TypeID from a string
parsed_id = TypeID.from_string(user_id_str)
print(f"Parsed TypeID: {parsed_id}")
# Compare TypeIDs
assert user_id == parsed_id