Skip to main content

cuid2

Python PyPi PyPi

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.

📝 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 (optionally specifying a custom length):

$ cuid2
$ cuid2 10

Or you can rely on a CUID wrapper if you only need default or custom-length generation:

from typing import Callable
from cuid2 import cuid_wrapper

cuid_generator: Callable[[], str] = cuid_wrapper()
short_cuid_generator: Callable[[], str] = cuid_wrapper(length=10)


def main():
    my_cuid: str = cuid_generator()
    short_cuid: str = short_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()

    # Validate CUID
    print(Cuid.is_cuid(my_cuid))  # True

Cuid.is_cuid also accepts optional min_length and max_length arguments to tighten the allowed length. The bounds are clamped to 2 and 98 characters, so they can narrow but never widen what is considered valid.

Metadata

Release files for cuid2 2.0.4

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.4
File Size Uploaded Provenance Actions
cuid2-2.0.4.tar.gz 8.9 kB Without provenance Details for cuid2-2.0.4.tar.gz

Built distribution (wheel)

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

Total release size: 18.2 kB

Release files / cuid2-2.0.4.tar.gz

Download URL cuid2-2.0.4.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b05d43771153458d022656a5b0747619a7b9ce0aa1b58f381d00d6a14bcad56a
BLAKE2b-256 checksum
How to use checksums
537034825cefbcc5542cdfcc352b12ee6dfe5613f975fa8e8b1d7d6bbee1f25c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

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

Download URL cuid2-2.0.4-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50290747d61e2d3ae378efbe5d318d6b2e6a71d8713eb092b2fb1a775cd1705c
BLAKE2b-256 checksum
How to use checksums
f3716ce61542217b05f24e40fd02ced072b8d77178cfc93cf1fd28b66a2eca32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for cuid2 2.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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