Skip to main content

Automatically detect and mask secrets in strings and dicts.

Project description

philiprehberger-secret-mask

Tests PyPI version Last updated

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 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
_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:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

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

philiprehberger_secret_mask-0.1.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_secret_mask-0.1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_secret_mask-0.1.1.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_secret_mask-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b8833e1db9fa46057dacf1766c62a527e4e4b4eb9d0219f78ab567633019d396
MD5 454be3f36e7a83726c952a2a7c2ca30e
BLAKE2b-256 ce608a29ce1d620f55195fb41125fc0e78cabdca2020715ff6f0bf3293f5dd52

See more details on using hashes here.

File details

Details for the file philiprehberger_secret_mask-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_secret_mask-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0ee2ed47d977fec177e76c571bc414a34cbc2e0a19dae0cd56b1977b7c75ec0d
MD5 cf690709bbb39fdf5d19dc321753abe0
BLAKE2b-256 a469a3b1f70d2a9ed8d9c5ed1241aa0e9cf6e73b8f26c0d4a48aafc604eaeacd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page