philiprehberger-secret-mask
Automatically detect and mask secrets in strings and dicts.
Installation
pip install philiprehberger-secret-mask
Usage
from philiprehberger_secret_mask import mask_secrets
data = {"username": "alice", "password": "hunter2", "api_key": "sk-abc123def456ghi789jk"}
safe = mask_secrets(data)
# {"username": "alice", "password": "***ter2", "api_key": "******************89jk"}
Masking Strings
from philiprehberger_secret_mask import mask_secrets
log_line = "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkw"
safe_log = mask_secrets(log_line)
# Bearer token is replaced with asterisks, last 4 chars visible
Checking Key Names
from philiprehberger_secret_mask import is_secret_key
is_secret_key("db_password") # True
is_secret_key("api_key") # True
is_secret_key("username") # False
Custom Patterns
from philiprehberger_secret_mask import register_pattern, register_key, mask_secrets, is_secret_key
# Register a custom regex pattern for string scanning
register_pattern(r"CUSTOM-[A-Za-z0-9]{8,}")
mask_secrets("key is CUSTOM-abcdefghij")
# "key is **************ghij"
# Register a custom key name for dict masking
register_key("ssn")
is_secret_key("ssn") # True
mask_secrets({"ssn": "123-45-6789"})
# {"ssn": "*******6789"}
Custom Masking
from philiprehberger_secret_mask import mask_value
mask_value("supersecret", mask_char="#", reveal_last=2)
# "#########et"
API
| Function / Constant | Description |
|---|---|
mask_secrets(data, *, mask_char, reveal_last) |
Detect and mask secrets in a string, dict, or list |
mask_value(value, *, mask_char, reveal_last) |
Mask a single string value |
is_secret_key(key) |
Check if a key name matches known secret patterns |
register_pattern(pattern) |
Register a custom regex pattern for secret detection |
register_key(key) |
Register a custom key name for secret key detection |
_SECRET_PATTERNS |
Compiled regexes for secret patterns in strings |
_SECRET_KEY_NAMES |
Set of key name substrings that indicate secrets |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Metadata
Release files for philiprehberger-secret-mask 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| philiprehberger_secret_mask-0.2.0.tar.gz | 6.5 kB | Without provenance | Details for philiprehberger_secret_mask-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| philiprehberger_secret_mask-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for philiprehberger_secret_mask-0.2.0-py3-none-any.whl |
Total release size: 11.6 kB
Release files / philiprehberger_secret_mask-0.2.0.tar.gz
| Download URL | philiprehberger_secret_mask-0.2.0.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56e8c47aebaff6e285b71a5b60774af46066fd0bf967779dc47f7a37306086e6
|
|
BLAKE2b-256 checksum How to use checksums |
02b0f6ce14a1f7482760a2b94b5fee63cc87166f367e55a70debf8d39ca59f6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_secret_mask-0.2.0-py3-none-any.whl
| Download URL | philiprehberger_secret_mask-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0267413952273486984f86381e1cc40f838230dfcd1cc9e7c9bfadf55f105f14
|
|
BLAKE2b-256 checksum How to use checksums |
d6f21aee61ca3177c6f8bd8ce73f1880c14003802f0a1dcd9ca8268a3202437e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for philiprehberger-secret-mask 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.