Install & Compatibility
Where this runs
tested against v1.0.0 · 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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.011s · 17.8MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.5s · import 0.008s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
decode
✓ from basicauth import decode
✗ import basicauth
encode
✓ from basicauth import encode
b64decode
✓ from basicauth import b64decode
This quickstart demonstrates how to use `basicauth.decode` to extract username and password from an 'Authorization' header, and `basicauth.verify` to check credentials. It highlights handling `None` returns for invalid headers.
import basicauth
# Example Authorization header
auth_header_valid = 'Basic Zm9vOmJhcg==' # 'foo:bar'
auth_header_invalid = 'Bearer eyJh...' # Not Basic Auth
auth_header_malformed = 'Basic not_base64'
# --- Decoding a Basic Auth header ---
# Returns (username, password) or None
username, password = basicauth.decode(auth_header_valid)
if username and password:
print(f"Decoded (valid): Username='{username}', Password='{password}'")
else:
print(f"Failed to decode (valid): {username=}, {password=}")
username_invalid, password_invalid = basicauth.decode(auth_header_invalid)
if username_invalid is None:
print(f"Decoded (invalid type, correctly None): {username_invalid=}, {password_invalid=}")
username_malformed, password_malformed = basicauth.decode(auth_header_malformed)
if username_malformed is None:
print(f"Decoded (malformed, correctly None): {username_malformed=}, {password_malformed=}")
# --- Verifying a Basic Auth header ---
# Returns True or False
is_valid_auth = basicauth.verify(auth_header_valid, 'foo', 'bar')
print(f"Verification (correct credentials): {is_valid_auth}")
is_invalid_auth = basicauth.verify(auth_header_valid, 'wrong', 'credentials')
print(f"Verification (incorrect credentials): {is_invalid_auth}")
is_invalid_format = basicauth.verify(auth_header_invalid, 'foo', 'bar')
print(f"Verification (wrong header format): {is_invalid_format}")
Debug
Known issues
gotchaThe `basicauth.decode()` function returns `None` if the provided `auth_header` is malformed, not a 'Basic' type header, or cannot be base64 decoded and split. It does not raise an exception in these cases.fixAlways check if the result of `basicauth.decode()` is not `None` before attempting to unpack or use the returned username and password. Example: `result = basicauth.decode(header); if result: username, password = result`.
affects: 1.0.0
gotchaThis library is intentionally simplistic. It only handles the decoding and basic verification of HTTP Basic Auth headers. It does not provide functionality for user management, password hashing, session management, token expiry, or integration with web frameworks.fixUse `basicauth` to obtain the username and password, then implement your application's specific logic for user lookup, password verification (e.g., using `bcrypt` or `argon2`), and session management within your web framework's request handlers.
affects: 1.0.0
breakingThe library is stable at version 1.0.0. While no breaking changes are known or anticipated for minor versions, be aware that any future major version increment (e.g., to 2.0.0) could introduce API changes.fixAlways pin your dependency version (e.g., `basicauth==1.0.0`) and review the changelog if upgrading to a new major version.
affects: < 1.0.0 to 1.0.0
Upgrade
Version history
1.0.0latest on PyPI · released Dec 23, 2022
Audit
Dependencies
No dependency data recorded yet.