Type Stubs for Passlib
types-passlib is a type stub package providing static type annotations for the 'passlib' library. It allows type checkers like Mypy and Pyright to analyze code that uses passlib. This package specifically targets passlib version 1.7.*. As of its latest release (1.7.7.20260211), the package is unmaintained, and any fixes or updates to the type stubs should be contributed directly to the `typeshed` project on GitHub. The upstream `passlib` library itself has maintenance concerns.
Warnings
- deprecated The `types-passlib` package is officially unmaintained and will not receive further updates on PyPI. All contributions and fixes for `passlib` type stubs should be directed to the `typeshed` project on GitHub.
- gotcha The upstream `passlib` library has known compatibility issues with `bcrypt` versions >= 4.1.0, leading to `AttributeError` during password hashing. This is due to `passlib` internally expecting an attribute that was removed in newer `bcrypt` versions.
- breaking The `passlib` library itself, for which these stubs are provided, is largely unmaintained (last release 1.7.4 in 2020) and has potential breakage in Python 3.13 due to the removal of the `crypt` module. While `passlib` has a fallback, its long-term compatibility and security posture are uncertain.
Install
-
pip install types-passlib -
pip install passlib
Imports
- CryptContext
from passlib.context import CryptContext
- hash
from passlib.hash import bcrypt
Quickstart
from passlib.context import CryptContext
import os
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
def hash_password(password: str) -> str:
return pwd_context.hash(password)
def verify_password(password: str, hashed_password: str) -> bool:
return pwd_context.verify(password, hashed_password)
# Example usage
plain_password = os.environ.get('TEST_PASSWORD', 'mysecretpassword')
hashed = hash_password(plain_password)
print(f"Hashed password: {hashed}")
is_valid = verify_password(plain_password, hashed)
print(f"Password valid: {is_valid}")
is_invalid = verify_password('wrongpassword', hashed)
print(f"Wrong password valid: {is_invalid}")