This nice, small module is used for generating cryptographically strong, random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets. It was added in Python 3.6, and basically deals with three things: random numbers, tokens, and digest comparison. Let's explore them very quickly.
Secrets
Random numbers
We can use three functions in order to deal with random numbers:
# secrs/secr_rand.py
import secrets
print(secrets.choice('Choose one of these words'.split()))
print(secrets.randbelow(10 ** 6))
print(secrets.randbits(32))
The first one, choice, picks an element at random from a non-empty sequence. The second one, randbelow, generates a random integer between...