larztotp
TOTP/HOTP two-factor auth codes. Pure Python (stdlib), zero dependencies.
Generate and verify the 6-digit one-time passwords authenticator apps use (Google
Authenticator, Authy, 1Password), plus the provisioning otpauth:// URI for the
setup QR — all from the standard library, matching the RFC test vectors so codes
interoperate with every app.
from larztotp import TOTP
totp = TOTP.generate() # new random secret
uri = totp.provisioning_uri("alice@example.com", issuer="MyApp") # QR this
totp.verify(user_entered_code) # True / False
Why
- Standards-correct. HOTP (RFC 4226) and TOTP (RFC 6238), tested against the published RFC vectors — the codes match real authenticator apps exactly.
- Skew-tolerant, safe verify. A configurable time
windowaccepts a slightly off clock; comparison is constant-time. - Zero dependencies. Pure
hmac/hashlib/base64— nopyotp, nothing to install. A natural companion to larzcrypt.
Install
pip install larztotp
Usage
from larztotp import TOTP, hotp, totp, verify, generate_secret
t = TOTP.generate(); t.now(); t.verify(code, window=1)
t.provisioning_uri("bob@x.com", issuer="App")
# or the raw functions
secret = generate_secret()
hotp(secret, counter=0)
totp(secret) # current 6-digit code
verify(secret, code, window=1)
SHA256/SHA512 and 8-digit codes are supported via algorithm=/digits=.
Tests
python -m unittest discover -s tests -v # 15 tests incl. RFC 4226/6238 vectors
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter — see larzcrypt and larzid.
License
MIT © larz-scripter
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file larztotp-0.1.0.tar.gz.
File metadata
- Download URL: larztotp-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19abac2a505fa3721b51545ef518d6a812daacb0edb8325bc50d7039eee1db2d
|
|
| MD5 |
49751466be567f8d424944bb1c18f1fd
|
|
| BLAKE2b-256 |
a2b8ff438a623164437a1f3e7b20342555209d1666e5751b24917a90af0b3a00
|
File details
Details for the file larztotp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larztotp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f605c9aa9f6205dca272bfe4cfb64e30f780e6517c5f0cd85dd1a9b071731c7
|
|
| MD5 |
ecd231ed643490822117f38550c4e2ad
|
|
| BLAKE2b-256 |
ed31598d7aaf020ac13984ba2a691cfd2ced7838f5e6d649bdf48eb337f04b58
|