Registry / auth-security / basicauth

basicauth

JSON →
library1.0.0pypypi✓ verified 83d ago

The `basicauth` library provides an incredibly simple implementation for HTTP Basic Authentication in Python. It focuses purely on decoding and basic verification of the 'Authorization' header. The current version is 1.0.0. The project is stable and has a low release cadence.

pip install basicauth
INSTALL
IMPORT
SIG · BASICAUTH
B
basicauth
auth-securitypythonv1.0.0
Install
1.5s avg
Import
11ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.011s · 17.8MB
glibc
py 3.103.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.
fix
Always 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.
fix
Use `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.
fix
Always 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.

Agent activity
22 hits · last 30 days
node
19
OpenAI (training)
1
Resources
basicauth — pip install basicauth · libregistry