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.
Project description
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 and Unique: Generates small, collision-resistant IDs suitable for distributed systems.
- Customizable: Supports custom random number generators and configurable options for maximum flexibility.
- Lightweight and Fast: Designed for performance without unnecessary dependencies.
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scuid-0.1.0.tar.gz.
File metadata
- Download URL: scuid-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbf0e414529c5c27194d114d383410be8d0321b3895fa19964bf12548d11189c
|
|
| MD5 |
3b5acfc24a04c5660629e79182db8534
|
|
| BLAKE2b-256 |
4ca8b0da04fb24a89a59c33196c6561da1718e96784ff8cef7097a0c9fa5dd1c
|
Provenance
The following attestation bundles were made for scuid-0.1.0.tar.gz:
Publisher:
release.yml on lh0x00/scuid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scuid-0.1.0.tar.gz -
Subject digest:
fbf0e414529c5c27194d114d383410be8d0321b3895fa19964bf12548d11189c - Sigstore transparency entry: 153820317
- Sigstore integration time:
-
Permalink:
lh0x00/scuid@a79bec523c6d975ecc0b80d08da7c5c019494be5 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/lh0x00
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a79bec523c6d975ecc0b80d08da7c5c019494be5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file scuid-0.1.0-py3-none-any.whl.
File metadata
- Download URL: scuid-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c0adce1387c762915ced6f2b867114e7050aa6afa7fa65e6f5bb6d0530fbb07
|
|
| MD5 |
bcc1ddc8a99571b02545c1b0f9dff0f5
|
|
| BLAKE2b-256 |
70ff8d95cb30fa4eacb456cb89cd427026354159b2fcdf460d1846a322875a24
|
Provenance
The following attestation bundles were made for scuid-0.1.0-py3-none-any.whl:
Publisher:
release.yml on lh0x00/scuid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scuid-0.1.0-py3-none-any.whl -
Subject digest:
9c0adce1387c762915ced6f2b867114e7050aa6afa7fa65e6f5bb6d0530fbb07 - Sigstore transparency entry: 153820318
- Sigstore integration time:
-
Permalink:
lh0x00/scuid@a79bec523c6d975ecc0b80d08da7c5c019494be5 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/lh0x00
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a79bec523c6d975ecc0b80d08da7c5c019494be5 -
Trigger Event:
push
-
Statement type: