secrets
Cryptographically strong random values for passwords, tokens and keys.
Easy
import secrets
secrets.token_urlsafe(32) # e.g. for a reset link
secrets.choice("0123456789")
Always use secrets, not random, for anything security-related.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.