Maintained. Last release 5 weeks ago, commits in 4 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install python-pampython-pam
Python pam module supporting py3 for Linux type systems (!windows)
Security
See SECURITY.md for supported versions and how to report vulnerabilities.
Threading and concurrency
pam.authenticate() is safe to call from many threads at once. Each call uses
its own PAM handle; libpam ctypes bindings are loaded once and shared (no global
lock on the auth path).
Do not share a single PamAuthenticator / pam.pam() instance across threads
without external synchronization. That object owns mutable PAM session state
(handle, code, reason, messages). For sessions (call_end=False), keep
one instance per thread (or serialize access).
High-QPS login APIs should use:
import pam
if pam.authenticate(username, password, service='myapp'):
...
Credentials (resetcreds)
After a successful pam_authenticate + pam_acct_mgmt, authenticate() calls
pam_setcred(..., PAM_REINITIALIZE_CRED) when resetcreds=True (the default).
Keep the default (True) when this process is acting like a login / credential
handoff: modules may establish or refresh credentials (e.g. Kerberos), and you care
about that step succeeding as part of auth.
Set resetcreds=False when you only need to verify a username/password (typical
web/API “is this password valid?” checks). You are not assuming the user’s identity
or opening a session; skipping setcred avoids extra module work and avoids treating a
setcred failure as an authentication failure.
# Password check only
pam.authenticate(user, password, service='myapp', resetcreds=False)
# Login-style / credential-aware stack (default)
pam.authenticate(user, password, service='login')