Skip to main content

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

philiprehberger_masked_print-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_masked_print-0.1.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_masked_print-0.1.1.tar.gz
Algorithm Hash digest
SHA256 696e12a9159d4c166d9488857a8be33cb96b17d900e208f124ba66ae62a4c577
MD5 1d98e4ac6dfbbfc9978fdae91fb9232f
BLAKE2b-256 8e6ae5d67385dcde4e185e9fb7ce767cecb1912cf2309f437315ea583fba5f63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_masked_print-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 35a59f9c22670b4a5c5cee5e44a55292e8d475e7a25cc71a58bf69cb93b7e895
MD5 f3d1e88cd0e5ee674d8e21e8fd646154
BLAKE2b-256 94bdabade2c9e7d64b8aa71f6f05a4e04607cf9fd91598ee5993f7e730a09fd0

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