pyrandstring
Random string generation (passwords, identifiers) backed by a cryptographically secure source from the standard library.
Works on Python 2.7 and 3.x. On Python 3.6+ it uses secrets.choice; on earlier
versions it falls back to random.SystemRandom, which draws from os.urandom -
the same source secrets uses internally. The global random generator, which
is predictable, is never used.
Installation
pip install pyrandstring
Usage
from pyrandstring import pyrandstring
p = pyrandstring()
p.getString() # 18 characters from the full alphabet
p.getString(32) # 32 characters from the full alphabet
p.getString(12, 'anum') # 12 alphanumeric characters
p.getStringUnique() # '1706462498_Xk2pQm9WvBn4TzLc'
p.getUUID() # '4e9abb2e-9bcc-40c7-bd6f-3021c5e3a0ad'
p.getStringList(3, 12) # ['6nINov%F(W6s', ',m4AwzBPlPe2', 'AeV7SNGclLVM']
Defaults can be set per instance:
p = pyrandstring()
p.length = 32
p.seed = 'bash'
p.getString() # 32 characters, 'bash' alphabet
Passing length or seed to getString() affects that call only; the
instance defaults are left untouched.
Alphabets
seed |
Characters | Size |
|---|---|---|
abc |
A-Z a-z |
52 |
num |
0-9 |
10 |
anum |
A-Z a-z 0-9 |
62 |
all |
anum + !"#$%&()*+,-./{|}~@ |
81 |
bash |
all without " ( ) |
78 |
zsh |
alias of bash |
78 |
all is the default alphabet. bash omits the symbols that need escaping when
the string is passed through a shell; zsh is an alias for it.
An unknown seed raises KeyError.
API
getString(length=None, seed=None)
Returns a random string of length length. When omitted, uses self.length
(18) and self.seed ('all').
getStringUnique()
Returns <unix_timestamp>_<16 alphanumeric characters>. Intended for filenames
and keys that also need to sort by time.
getUUID()
Returns a random UUID (version 4) as a string.
getStringList(quantity, length=None, seed=None)
Returns a list of quantity random strings. length and seed behave exactly
as in getString(), and the instance defaults are left untouched.
p.getStringList(5, 16, 'anum')
Tests
python -m unittest discover tests -v
License
GPL-3.0. See LICENSE.txt.
Metadata
Release files for pyrandstring 0.1.0
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 |
|---|---|---|---|---|
| pyrandstring-0.1.0.tar.gz | 18.5 kB | Without provenance | Details for pyrandstring-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyrandstring-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pyrandstring-0.1.0-py3-none-any.whl |
Total release size: 34.6 kB
Release files / pyrandstring-0.1.0.tar.gz
| Download URL | pyrandstring-0.1.0.tar.gz |
|---|---|
| Size | 18.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8e57e1bed133957a8bedc999504c3fb0bf83897dfb1bd74402966dd67f83688
|
|
BLAKE2b-256 checksum How to use checksums |
87820a4bd5f6d23d88ad7c0f160c1afae121170d4cfd7dca101e1d4b7db590b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / pyrandstring-0.1.0-py3-none-any.whl
| Download URL | pyrandstring-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f6d815a062af73c91a0443a5e00c4470f9ec4ea6107aadd12df30af0373bfbf
|
|
BLAKE2b-256 checksum How to use checksums |
480b3a7a53a3cb848530436498d335aa5452506ddc8eaeec440d7129150a15c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for pyrandstring 0.1.0
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.