Human Short Code
Encode integers into compact, human-readable codes and decode them reliably.
Useful for generating invitation codes, referral links, tracking IDs, or session tokens.
Features
- Encode numbers into fixed-length readable codes
- Decode codes back to original numbers
- Validate code format
- Customizable alphabet and length
- Mid-string hyphen for clarity
Installation
pip install human-short-code
Or install from source:
git clone https://github.com/yourusername/human-short-code.git
cd human-short-code
python -m build
pip install dist/*.whl
Usage
from human_short_code import encode, decode, verify
number = 123456789
# Encode number
code = encode(number)
print(code) # e.g. 'QIUN-ESAD'
# Decode code
original = decode(code)
print(original) # 123456789
# Verify code format
print(verify(code)) # True
API
encode(id_number: int, alphabet: str = ..., length: int = ...) -> str
Convert an integer into a short, fixed-length alphanumeric code.
- id_number: Integer to encode
- alphabet: Optional custom alphabet (default: "ASDEIUNWRQXBOKH")
- length: Total code length excluding hyphen (default: 8)
Returns a code string with a hyphen inserted at the center.
decode(code: str, alphabet: str = ..., length: int = ...) -> int
Decode a code string back into the original integer.
- code: Code string to decode
- alphabet: Optional custom alphabet used in encoding
- length: Expected code length excluding hyphen
Raises ValueError if invalid input.
verify(code: str, alphabet: str = ..., length: int = ...) -> bool
Check if a code is valid for the given alphabet and length.
- code: Code string to verify
- alphabet: Optional alphabet to validate against
- length: Maximum code length excluding hyphen
Returns True if valid, False otherwise.
Customization
custom_alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ"
custom_length = 6
code = encode(987654, custom_alphabet, custom_length)
print(code) # e.g. 'BAC-DEF'
number = decode(code, custom_alphabet, custom_length)
print(number) # 987654
Tests
pytest
License
MIT
Metadata
Release files for human-short-code 1.0.2
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 | |
|---|---|---|---|---|
| human_short_code-1.0.2.tar.gz | 4.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| human_short_code-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / human_short_code-1.0.2.tar.gz
| Download URL | human_short_code-1.0.2.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f44a459da1437285f5c4581fea35680f1620921eb8b3ac16d85569db97f70062
|
|
BLAKE2b-256 checksum How to use checksums |
f7f7b4f8a770cb68feee2a13b72d05cfda5632dc218f2851d571e37ccafa3eed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.2
|
Release files / human_short_code-1.0.2-py3-none-any.whl
| Download URL | human_short_code-1.0.2-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc8cfaa4c21c6b5dd69ae4a320464c1b35ad7fd3ed8744de0e074ad32a3d0be6
|
|
BLAKE2b-256 checksum How to use checksums |
34f0635700365167c4f3a86ee46b554f2ba4d65b5a1595a9e7d99155d1d9a53f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.2
|
Security for human-short-code 1.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.