Crockford Base32 ID generation and validation
Project description
IDCrockford
Crockford Base32 ID encoder/decoder with FastAPI dependency injection support for validation and generation of Crockford Base32 IDs.
idcrockford has 3 interfaces:
- CLI
- Library
- FastAPI dependency
Installation
pip install idcrockford
or using uv:
uvx idcrockford
CLI
uvx idcrockford --help
usage: idcrockford [-h] [--checksum] [--split SIZE] [--padding] [--strict] {encode,decode,normalize,generate} [input]
Crockford Base32 Utility
positional arguments:
{encode,decode,normalize,generate}
Operation to perform
input Input to process. For encode: integer or string. For generate: size (optional)
options:
-h, --help show this help message and exit
--checksum Add/validate checksum symbol
--split SIZE Split encoded string with hyphens (chunk size, default: no splitting)
--padding Add padding characters (=) to output
--strict Strict mode for normalize command - error if normalization needed
Library
from idcrockford import Base32Crockford
crockford = Base32Crockford(
checksum=True,
split=4,
padding=True,
)
# Encode and decode
crockford.encode(1234567890) # 14SC-0PJV
crockford.decode("14SC-0PJV") # 1234567890
# Generate
crockford.generate() # 16 random characters
crockford.generate(size=10) # 10 random characters
crockford.generate(size=10, checksum=True, split=4, padding=True) # 10 random characters with checksum, split and padding
# TODO: add normalize
crockford.normalize("14SC-0PJV") # 14SC0PJV
FastAPI Dependency
from fastapi import FastAPI, Depends
from idcrockford import CFIdentifierConfig
IdentifierConfig = CFIdentifierConfig(checksum=True, size=16)
app = FastAPI()
@app.get("/items/{id}")
def read_item(id: str = Depends(IdentifierConfig.validate)):
return {"id": id}
@app.post("/items/")
def create_item(id: str = Depends(IdentifierConfig.generate)):
return {"id": id}
Roadmap
- Add
normalizemethod toCFIdentifierConfig - Support Pydantic custom type for Crockford Base32 ID validation and generation
License
MIT
Other packages
- inveniosoftware/base32-lib - Python Base32 encoder/decoder with no padding
- jbittel/base32-crockford - JavaScript Base32 encoder/decoder with Crockford checksum
- DrSLDR/krock32 - Kotlin Base32 encoder/decoder with Crockford checksum
- pat-jpnk/Crockford-Base32 - JavaScript Base32 encoder/decoder with Crockford checksum
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
idcrockford-0.1.2.tar.gz
(5.2 kB
view details)
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 idcrockford-0.1.2.tar.gz.
File metadata
- Download URL: idcrockford-0.1.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e222fefcb7fb7fcdb432e2d2e4a8c8f1afa0a6f14d585ebfd8a39cf05423c1b1
|
|
| MD5 |
63a7f36c48091da3914a0be76e88d212
|
|
| BLAKE2b-256 |
494d611e6e64790d7141f880300613d9cc24e5f2034fe690e8c336dc482d6f94
|
File details
Details for the file idcrockford-0.1.2-py3-none-any.whl.
File metadata
- Download URL: idcrockford-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9df943e5d6e11f1947c810943fbbca6afe3975dc3841202eaf31bd439611f9bf
|
|
| MD5 |
f2bb60d76493baae1c6db4d68ac54667
|
|
| BLAKE2b-256 |
99b052637c21f1c43e0fbb0184842f12e8d49d510a9a128f377b4df6601a7cec
|