Larz โ€บ TOTP 2FA in Python

Two-factor auth in Python, without a library

Larz ships standards-based TOTP (RFC 6238) that works with Google Authenticator, Authy and 1Password โ€” built on the standard library, no pyotp, no extra install.

pip install larz
import larz.auth as auth, larz.twofa as twofa
auth.enable(app); twofa.enable(app, issuer="MyApp")

uri, secret = app.twofa.begin(req.user)      # render `uri` as a QR code
codes = app.twofa.activate(req.user, code)   # one-time backup codes

@app.twofa_required
@app.get("/billing")
def billing(req): ...

QuickstartGitHubFree course

What you get

FAQ

Does it work with Google Authenticator?

Yes. Larz implements standard TOTP (RFC 6238), so Google Authenticator, Authy, 1Password and Microsoft Authenticator all work.

Do I need a third-party library?

No โ€” the TOTP code is built on Python's hmac and base64 modules. Larz stays zero-dependency.

What about lost devices?

Enrolment returns one-time backup codes; app.twofa.verify() accepts either a live TOTP code or an unused backup code.