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

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.3
File Size Uploaded Provenance Actions
cuid2-2.0.3.tar.gz 9.0 kB Without provenance Details for cuid2-2.0.3.tar.gz

Built distribution (wheel)

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

Total release size: 18.3 kB

Release files / cuid2-2.0.3.tar.gz

Download URL cuid2-2.0.3.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5c74cb8d641ad960780e00c7eb6253c03256a5f194be98c6c2196fd4035cfd2a
BLAKE2b-256 checksum
How to use checksums
8f544960d207b2a32a87746eb472c13251c0078c5770ac691bcd7aa1f8242f60
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.3-py3-none-any.whl

Download URL cuid2-2.0.3-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76ef9a8708e2a67eac6b805325f357777ed35eb2c44373f2e8d3a2c6cc4aeee7
BLAKE2b-256 checksum
How to use checksums
2a9a00a0289496c28041529aea12bd799fe65e939bb80f47c15e79f2066fe5f5
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.3

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