Registry / auth-security / python-pam

python-pam

JSON →
library2.0.2pypypi✓ verified 25d ago

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.

pip install python-pam
INSTALL
IMPORT
SIG · PYTHON-PAM
P
python-pam
auth-securitypythonv2.0.2
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pam
import pam
import pam

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}")
Debug
Known issues
breakingThe `authenticate()` method's return type changed from a boolean to a PAM constant in version 2.0.0, and then reverted to a boolean in 2.0.2. Code expecting a boolean in 2.0.0 would have broken. Always check the return value against `True`/`False` or the specific PAM constant for 2.0.0 if targeting that version.
fix
Ensure your code checks for `True` or `False` return values from `authenticate()`. If specifically targeting 2.0.0, verify against the PAM constant, otherwise boolean is standard in 2.0.2+.
affects: 2.0.0
gotchaThe library adheres to standard PAM privilege rules: if running as root (or with privileged access), you can check any account's password. If not running as root, you can generally only check the validity of the username running the tool.
fix
Design your application with appropriate privilege separation. For authenticating multiple users in a non-privileged context, consider an authentication stack like SSSD on Linux.
affects: All versions
deprecatedWhile Python 2 support was intentionally left in for version 2.0.0, the project README explicitly states that Python 2 support is deprecated.
fix
Migrate any Python 2 usage to Python 3 as future support is not guaranteed and actively discouraged.
affects: 2.0.0+
gotchaThe functionality of `python-pam` is entirely dependent on the underlying system's PAM configuration (e.g., files in `/etc/pam.d/`). Misconfiguration of PAM on the host system will lead to authentication failures or unexpected behavior within your Python application.
fix
Familiarize yourself with PAM configuration on your target system. Ensure the relevant PAM service (`/etc/pam.d/system-auth` or a custom service) is correctly configured for the desired authentication methods.
affects: All versions
gotchaThis library is designed for Unix-like operating systems (specifically Linux) and does not support Windows.
fix
Deploy applications using `python-pam` only on Linux or other compatible Unix-like systems. For Windows authentication, consider alternative libraries or methods.
affects: All versions
Upgrade
Version history
2.0.2latest on PyPI · released Mar 18, 2022
Audit
Dependencies
linux-pamrequiredRequires the underlying system's PAM library and development headers (e.g., libpam0g-dev on Debian-based systems) to build and function correctly.
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
python-pam — pip install python-pam · libregistry