ImportError: cannot import name 'hash_secret_raw' from 'argon2'
Explains why `from argon2 import hash_secret_raw` throws ImportError and how to fix it by importing from `argon2.low_level` instead. Use when you need the raw KDF bytes rather than the PasswordHasher string format. Not for PasswordHasher import problems.
ImportError: cannot import name 'hashsecretraw' from 'argon2'
TL;DR: the low-level KDF functions live in argon2.low_level, not at the top level. Use from argon2.low_level import hash_secret_raw and it imports fine.
ImportError: cannot import name 'hash_secret_raw' from 'argon2'The fix
from argon2.low_level import hash_secret_raw, Type
raw = hash_secret_raw(b"password", b"somesalt16bytes!", time_cost=2, memory_cost=102400, parallelism=8, hash_len=32, type=Type.ID)Verify:
python -c "from argon2.low_level import hash_secret_raw; print('ok')"Expected output: ok.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=argon2+hash_secret_raw+low_level'
When this applies
- You need raw key bytes for key derivation, not a password hash string.
- The top-level
argon2module imports fine but lacks the low-level names. - Following KDF examples that assume the low_level import path.
When it does NOT apply
No module named 'argon2', which means argon2-cffi is not installed.- Password hashing with encoded strings, where PasswordHasher is the right tool.
Why this happens
argon2-cffi deliberately keeps the raw bindings one level down so the friendly top-level namespace stays small. The lowlevel module mirrors the C API (hashsecret, hashsecretraw, verify_secret) and is the documented home for KDF work. Importing from the wrong level is just a wrong address, not a broken install.
Compatibility
argon2-cffi 18+. The low_level API has been stable across the 18-23 line.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.