Generate random readable strings for various purposes
pip install philiprehberger-randstrGenerate random readable strings for various purposes.
pip install philiprehberger-randstr
from philiprehberger_randstr import randstr
randstr(16) # "aBx4kLm9pQrS2tUv"
randstr(8, charset="lowercase") # "abcdefgh"
from philiprehberger_randstr import token, password
token(32) # URL-safe base64 token
password(16) # "aB3$kLm!9pQr#2tU"
from philiprehberger_randstr import hex_str, uuid_short
hex_str(16) # "a1b2c3d4e5f6a7b8"
uuid_short() # "7f3a8b2c"
readable_id excludes visually-confusable characters (0, 1, O, o, I, l) — useful for vouchers, short references, and any human-typed code.
from philiprehberger_randstr import readable_id
readable_id(8) # e.g. "K7P4MNXR" — never contains 0/1/O/o/I/l
All generators use the secrets module for cryptographic security.
| Function / Class | Description |
|---|---|
randstr(length=16, charset="alphanumeric") | Random string from a built-in or custom charset |
token(length=32) | URL-safe base64-encoded token |
password(length=16, symbols, min_symbols, min_digits, min_upper) | Strong password with guaranteed character-class diversity |
hex_str(length=16) | Random lowercase hex string |
uuid_short(length=8) | Short UUID-like hex ID |
readable_id(length=8) | Random ID drawn from a visually-unambiguous alphabet |
pip install -e .
python -m pytest tests/ -v
If you find this project useful: