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.2

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.2
File Size Uploaded Provenance Actions
cuid2-2.0.2.tar.gz 8.6 kB Without provenance Details for cuid2-2.0.2.tar.gz

Built distribution (wheel)

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

Total release size: 17.4 kB

Release files / cuid2-2.0.2.tar.gz

Download URL cuid2-2.0.2.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7ebfcd903f9b4af248fc6988f8c34e492ebfdf5dfc6ab1e2424683f35bf441d3
BLAKE2b-256 checksum
How to use checksums
b4d241f894f3ef7e657c7964695a0a0d3eb31e127aec73713a045b56fad22aa8
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.2-py3-none-any.whl

Download URL cuid2-2.0.2-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba41de359722a5d03c13d0b2ef54e3a9b45b825af4a1889c403124a94b47db40
BLAKE2b-256 checksum
How to use checksums
93eed6d013721833a193b706640b67679006ea9438a8e886395ee53870c3948b
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.2

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