scuid
scuid is a lightweight Python library for generating collision-resistant IDs optimized for horizontal scaling and high performance. It serves as a slim, alternative implementation of cuid with added flexibility for customization, including support for custom random number generators.
Whether you're building distributed systems or need compact, unique identifiers, scuid offers a simple and efficient solution.
It is a reference port of the scuid source code for Node.js
Why Use scuid?
- Compact, Unique, and Efficient: Generates small, collision-resistant IDs suitable for distributed systems. Compared to UUID v4, MD5, SHA1, and other collision-resistant ID generators, the shorter length of scuid IDs reduces the number of characters and tokens used. This makes scuid particularly advantageous for applications like generative AI, where minimizing token usage is often crucial.
- Customizable and Flexible: Supports custom random number generators and configurable options, enabling tailored solutions for a wide range of use cases.
- Lightweight and High-Performance: Designed to deliver fast ID generation without introducing unnecessary dependencies, ensuring optimal performance.
For more information or to contribute, visit the GitHub repository.
Installation
Install scuid using pip:
pip install scuid
Quick Start
Generate a Unique ID
Create a unique identifier with just one line:
from scuid import scuid
id = scuid()
print(id)
# Example output: 'ciux3hs0x0000io10cusdm8r2'
Generate a Compact Slug
Slugs are shorter representations suitable for use in URLs or filenames:
from scuid import slug
slug_value = slug()
print(slug_value)
# Example output: '6x1i0r0'
Get the Process Fingerprint
The fingerprint represents the process and machine where the ID was generated:
from scuid import fingerprint
fp = fingerprint()
print(fp)
# Example output: 'io10'
Advanced Usage
Customize the Random Number Generator (RNG)
You can provide a custom random number generator by implementing a random() method:
from scuid import Scuid
class CustomRNG:
def random(self):
return 0.5 # Always returns 0.5 for demonstration purposes
custom_scuid = Scuid({"rng": CustomRNG().random})
id = custom_scuid.id()
print(id)
Configure Custom Options
You can customize the ID generation process to fit your requirements. Note that altering these options may affect compatibility with the default cuid behavior.
from scuid import Scuid
custom_scuid = Scuid({
"prefix": "c", # Prefix for generated IDs
"base": 36, # Radix for encoding (supports 2-36)
"blockSize": 4, # Size of each padded block
"fill": "0", # Padding character
"pid": 12345, # Custom process ID
"hostname": "customhost", # Custom hostname
"rng": lambda: 0.42, # Custom RNG function
})
id = custom_scuid.id()
print(id)
Testing
To verify the correctness and collision resistance of scuid, you can run the included tests:
pytest
The tests simulate real-world scenarios with millions of iterations to ensure the reliability of generated IDs.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for scuid 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scuid-0.3.3.tar.gz | 4.8 kB | With provenance | Details for scuid-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scuid-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for scuid-0.3.3-py3-none-any.whl |
Total release size: 9.8 kB
Release files / scuid-0.3.3.tar.gz
| Download URL | scuid-0.3.3.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d93747409acd33ec93ff11ca64a0a3202c49ecbc3a4f171318a1f23e84d384aa
|
|
BLAKE2b-256 checksum How to use checksums |
2fdf25c12316c7f832b0688827e63884fc12a189a3cf446f3d3a3d1b0e224124
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 27, 2025.
Transparency logRelease files / scuid-0.3.3-py3-none-any.whl
| Download URL | scuid-0.3.3-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac7553a1467ce5fe77ca104bfd0b011fb5d0291293785d08eb20e698adc59bbe
|
|
BLAKE2b-256 checksum How to use checksums |
27195124c94c78c9961b1eec3401cafc02d01423ab69583c2da37f8e5e16256a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 27, 2025.
Transparency logSecurity for scuid 0.3.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for scuid-0.3.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 27, 2025.
Transparency logA 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.