secretsEasy Examples

Cryptographically strong random numbers for tokens and passwords

Getting started with secrets

Basic import and usage of the secrets module.

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.

Common secrets operations

Frequently used functions from the secrets module.

python
# More secrets examples
import secrets

print(f"secrets module loaded successfully")
print(f"Location: {secrets.__name__}")
print(f"Has {len(dir(secrets))} attributes")

These are the most commonly used features of the secrets module.

Want to try these examples interactively?

Open Easy Playground