python-pam is a Python module that provides an interface to the Pluggable Authentication Modules (PAM) system on Unix-like operating systems using ctypes. It enables Python applications to perform user authentication tasks by leveraging the underlying system's PAM configuration. The current version is 2.0.2. Releases are primarily driven by bug fixes and compatibility updates.
Install & Compatibility
Where this runs
tested against v2.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Initializes the PAM authentication object and attempts to authenticate a user with provided credentials. The `authenticate()` method returns `True` or `False`, and additional details are available in `p.code` and `p.reason`.
import pam
import os
p = pam.authenticate()
# For demonstration, use environment variables or default values.
# On a real system, you would get these from user input.
username = os.environ.get('PAM_TEST_USERNAME', 'testuser')
password = os.environ.get('PAM_TEST_PASSWORD', 'testpassword')
# Note: For successful authentication, 'testuser' and 'testpassword'
# must be valid credentials on the system where this code runs,
# and the PAM configuration must allow 'python-pam' to authenticate.
if p.authenticate(username, password):
print(f"Authentication successful for {username}. Code: {p.code}, Reason: {p.reason}")
else:
print(f"Authentication failed for {username}. Code: {p.code}, Reason: {p.reason}")
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.