cuid2: Next Generation GUIDs for Python

2.0.1 · active · verified Thu Apr 16

cuid2 is a Python 3 library providing next-generation Globally Unique Identifiers (GUIDs). It's a port of the CUID2 reference implementation, optimized for horizontal scaling and performance. CUID2 IDs are secure, collision-resistant, horizontally scalable, offline-compatible, and URL-friendly, making them ideal for modern distributed systems. The library is actively maintained, with the current version being 2.0.1, and receives regular updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the two primary ways to generate CUID2 identifiers: using the simple `cuid_wrapper` function for a callable generator, or instantiating the `Cuid` class for more granular control, such as specifying the ID length.

from cuid2 import cuid_wrapper, Cuid

# Method 1: Using the simplified wrapper (recommended for most cases)
cuid_generator = cuid_wrapper()
my_cuid = cuid_generator()
print(f"Generated CUID (wrapper): {my_cuid}")

# Method 2: Using the Cuid class for more control (e.g., custom length)
custom_cuid_generator = Cuid(length=10)
short_cuid = custom_cuid_generator.generate()
print(f"Generated CUID (custom length 10): {short_cuid}")

view raw JSON →