CUID (Collision-resistant Unique IDentifier)
cuid.py is a Python implementation of the original CUID (Collision-resistant Unique IDentifier) standard, designed for horizontally scalable and fast unique ID generation. It aims to provide portable and sequentially-ordered unique identifiers. The current version is 0.4. The upstream CUID standard (v1), which this library implements, has been deprecated in favor of CUID2 due to security considerations, so this library is not actively developed beyond maintenance for the deprecated standard.
Warnings
- breaking The original CUID standard (v1), implemented by this library, has been officially deprecated upstream due to security concerns. It leaks timestamps and other potentially predictable information, making it unsuitable for security-sensitive applications where IDs should not be guessable or reveal creation order. The successor is CUID2.
- deprecated This Python library implements the deprecated CUID v1 standard. While functional, it is no longer recommended for new development, especially where security or information leakage are concerns. The project appears to be in maintenance mode for this deprecated standard.
- gotcha The `cuid.slug()` function generates shorter, URL-friendly identifiers. However, slugs have less random data, less room for the counter and fingerprint, which increases the probability of collisions. They are explicitly NOT recommended for use as database unique IDs or primary keys where strong collision resistance is critical.
- gotcha CUIDs, including those generated by `cuid.py`, are string-based identifiers. When used as database primary keys, ensure that database columns are appropriately indexed for optimal performance. They are not intrinsically integers and may not perform as well with auto-incrementing integer primary key optimizations in some databases.
Install
-
pip install cuid
Imports
- cuid
import cuid
Quickstart
import cuid
# Generate a standard CUID
my_cuid = cuid.cuid()
print(f"Generated CUID: {my_cuid}")
# Generate a 'slug' (shorter, less collision-resistant, not for primary keys)
my_slug = cuid.slug()
print(f"Generated CUID slug: {my_slug}")