secrets
Stdlib — MathPython 2.0+Intermediate
Cryptographically strong random numbers for tokens and passwords
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
- Dependencies
- None — Python Standard Library
- Install
Included with Python
Learn by Difficulty
Quick Example
python
import secrets # Secure random values print(f"Token: {secrets.token_hex(16)}") print(f"URL-safe: {secrets.token_urlsafe(16)}") print(f"Random int: {secrets.randbelow(100)}")
The secrets module is part of Python's standard library. Cryptographically strong random numbers for tokens and passwords.
Try in PlaygroundTags
stdlibmathnumeric