PyDocs

Cryptographic Services

Cryptographic Services

secrets

Generate cryptographically strong pseudo-random numbers suitable for
managing secrets such as account authentication, tokens, and similar.

See PEP 506 for more information.
https://peps.python.org/pep-0506/
Symbols in secrets

c

choice
Choose a random element from a non-empty sequence.
compare_digest
Return 'a == b'.

d

DEFAULT_ENTROPY
Default number of bytes of randomness used by the token_* functions.

r

randbelow
Return a random int in the range [0, n).
randbits
getrandbits(k) -> x.

s

SystemRandom
Alternate random number generator using sources provided by the operating system (such as /dev/urandom on Unix or CryptGenRandom on Windows).

t

token_bytes
Return a random byte string containing *nbytes* bytes.
token_hex
Return a random text string, in hexadecimal.
token_urlsafe
Return a random URL-safe text string, in Base64 encoding.