Skip to main content

cuid2

Python PyPi PyPi cuid2

CUID2 for Python 3. Next generation GUIDs. Collision-resistant ids optimized for horizontal scaling and performance.

A port of the CUID2 reference implementation by Parallel Drive to Python 3.

:memo: Note: Originally taken from https://github.com/overflowdigital before it was unpublished. Thank you to @joshuathompsonlindley for your original contribution!

What is CUID2?

  • Secure: It's not possible to guess the next ID.
  • Collision resistant: It's extremely unlikely to generate the same ID twice.
  • Horizontally scalable: Generate IDs on multiple machines without coordination.
  • Offline-compatible: Generate IDs without a network connection.
  • URL and name-friendly: No special characters.

Why?

For more information on the theory and usage of CUID2, see the following.

Improvements Over CUID

For more information on the improvements of CUID2 over CUID, see the following.

Install

pip install cuid2

Usage

You can generate CUIDs directly in the terminal with the following:

$ cuid2

Or you can rely on a CUID wrapper if you don't need any customizations:

from typing import Callable
from cuid2 import cuid_wrapper

cuid_generator: Callable[[], str] = cuid_wrapper()

def main():
  my_cuid: str = cuid_generator()
  next_cuid: str = cuid_generator()

Finally, for more explicit control of the CUID generator, you can instantiate the class directly:

from cuid2 import Cuid

CUID_GENERATOR: Cuid = Cuid(length=10)

def main():
  my_cuid: str = CUID_GENERATOR.generate()
  next_cuid: str = CUID_GENERATOR.generate()

Metadata

Release files for cuid2 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cuid2 2.0.1
File Size Uploaded
cuid2-2.0.1.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cuid2 2.0.1
File Interpreter ABI Platform
cuid2-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / cuid2-2.0.1.tar.gz

Download URL cuid2-2.0.1.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8d262eb467c16b81419361e18e47f41da77c4446dd2cf0640eac2616680bc924
BLAKE2b-256 checksum
How to use checksums
db6397ffc74f33e5a5f913bf073e8250a5b5a64d52d411b09a9c36c902db2cc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via pdm/2.14.0 CPython/3.10.12 Linux/6.5.0-1017-azure

Release files / cuid2-2.0.1-py3-none-any.whl

Download URL cuid2-2.0.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
943bdf86dc3ed07f32253e1be6e3c34dda8c7bda1c453f851f4ebaaa5a2dcfbf
BLAKE2b-256 checksum
How to use checksums
00d290fce0050c5a9196d259ac8f0c4720c69ec6b5a322612edf3892f0036c5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via pdm/2.14.0 CPython/3.10.12 Linux/6.5.0-1017-azure

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page