MinTOTP - Minimal TOTP Generator

raw JSON →
0.3.0 verified Mon Apr 27 auth: no python maintenance

Minimal TOTP (Time-based One-Time Password) generator library. Current version 0.3.0. No known release cadence; last updated 2021.

pip install mintotp
error ValueError: Incompatible secret length
cause The secret string length is not a multiple of 8 (base32 padding requirement).
fix
Ensure the secret has proper base32 padding (e.g., add '=' characters if needed).
error AttributeError: module 'mintotp' has no attribute 'generate'
cause Trying to call a non-existent function. mintotp only provides `totp()` and `hotp()`.
fix
Use mintotp.totp(secret) instead of mintotp.generate(secret).
gotcha The secret must be base32 encoded (uppercase letters A-Z and digits 2-7). Providing a raw string will produce incorrect codes.
fix Use a base32 encoder like `base64.b32encode(key_bytes)` to convert your secret.
gotcha The default time step is 30 seconds. Ensure clock synchronization. The function expects Unix timestamps in seconds.
fix Use `int(time.time())` for current time. If using a different step, pass as third argument.

Generate and verify TOTP codes using a base32 secret.

import mintotp
import time

# Generate a TOTP using a secret (base32 encoded)
secret = "JBSWY3DPEHPK3PXP"
totp = mintotp.totp(secret)
print(totp)

# Verify a code
code = input("Enter code: ")
current_time = int(time.time())
print(mintotp.totp(secret, current_time) == code)