all Python 3until 3.13Linux · macOSRemoved from the standard libraryterm
spwd
removed modules
Read the shadow password database /etc/shadow. Unix-only. Removed in Python 3.13 with no stdlib replacement — check passwords via python-pam.
Syntax
import spwd # до 3.13
spwd.getspnam('alice') returned a record from /etc/shadow: the password hash sp_pwdp, its expiry and other fields; only root could read it. Usually the goal was to check a password by comparing the hash via crypt. PEP 594 dropped it together with crypt: reading hashes by hand is unsafe and bypasses the system login policy. There is no stdlib replacement. Delegate password checks to PAM through the python-pam package: pam.authenticate(name, password). Public user data (home directory, shell, UID) still comes from pwd.getpwnam(), which needs no root rights.
Examples
# Python 3.13+
try:
import spwd
except ModuleNotFoundError as e:
print(type(e).__name__) # → ModuleNotFoundError
# Python 3.13+
import pwd
print(pwd.getpwnam('root').pw_dir) # → /root
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy