Automatically mask sensitive values (API keys, passwords, tokens) in logs and print output
Project description
philiprehberger-masked-print
Automatically mask sensitive values (API keys, passwords, tokens) in logs and print output.
Install
pip install philiprehberger-masked-print
Usage
from philiprehberger_masked_print import mask, mask_dict, MaskedFormatter
# Mask a single string
masked = mask("sk-abc123secret456xyz")
# "sk-a*************xyz"
Mask dictionaries
config = {
"host": "localhost",
"password": "super-secret-value",
"database": {
"connection_string": "postgres://admin:pass@localhost/db",
},
}
safe = mask_dict(config)
# {
# "host": "localhost",
# "password": "supe***********lue",
# "database": {
# "connection_string": "post*****************/db",
# },
# }
Auto-mask log output
import logging
from philiprehberger_masked_print import MaskedFormatter
handler = logging.StreamHandler()
handler.setFormatter(MaskedFormatter("%(levelname)s: %(message)s"))
logger = logging.getLogger("app")
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
logger.info("Using key sk-proj-abc123def456ghi789jkl012mno")
# INFO: Using key sk-p*************************mno
API
| Function / Class | Description |
|---|---|
mask(value, *, show_first=4, show_last=3, mask_char="*") |
Mask a string, keeping the first and last N characters visible |
mask_dict(data, *, sensitive_keys=None, show_first=4, show_last=3) |
Recursively mask sensitive key values in a dictionary |
MaskedFormatter(fmt) |
Logging formatter that auto-redacts secret patterns (sk-..., eyJ..., AKIA..., URL credentials) |
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_masked_print-0.1.3.tar.gz.
File metadata
- Download URL: philiprehberger_masked_print-0.1.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e344e9c68e1374884693a11b6b4b62790b419057d6f944c0aa67a106df309799
|
|
| MD5 |
bdd86d9c4489885c705bcaf414146715
|
|
| BLAKE2b-256 |
771024c4577756f0eac596c78e0b9802b65920161c8777e8a77fc222da458c16
|
File details
Details for the file philiprehberger_masked_print-0.1.3-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_masked_print-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b43c907d8f128e9027a1fb13155ae6f4d0aef2eb9a33eb2e11cdcc9029559b6a
|
|
| MD5 |
cc1ec6bc5297683f9103c3cc657184d2
|
|
| BLAKE2b-256 |
8a997a28dd8fc8d4beee93902ea74152d47f05106ee508d71fe16617b9c7b734
|