Skip to main content

Lightweight sensitive data redaction for accidental printing of sensitive Python strings, dicts, and logs.

Project description

log-redactor

CI PyPI Python License

Small, dependency-free redaction helpers for Python logs and payloads.
log-redactor helps prevent accidental exposure of secrets in log messages, strings, and nested dictionaries.

Why use it?

  • Redacts by key name and regex pattern value matching
  • Supports nested dict / list / tuple structures
  • Works with standard library logging and %s-style args
  • Keeps runtime dependencies at zero (stdlib only)

Installation

pip install python-log-redactor

Quick start

import logging
from log_redactor import RedactingFilter, redact, redact_dict

logger = logging.getLogger("app")
logger.setLevel(logging.INFO)
logger.addFilter(RedactingFilter(patterns=["email", "jwt", "api_key"]))

logger.info("User %s used key %s", "alice@example.com", "sk-live-abc123")

print(redact("Contact: dev@example.com"))

payload = {
    "username": "alice",
    "password": "super-secret",
    "profile": {"email": "alice@example.com"},
}
print(redact_dict(payload))

API

from log_redactor import RedactingFilter, redact, redact_dict
  • redact(text: str, patterns=None, custom_patterns=None, replacement="[REDACTED]") -> str
  • redact_dict(data: dict, keys=None, patterns=None, custom_patterns=None, replacement="[REDACTED]") -> dict
  • RedactingFilter(logging.Filter)

Built-in patterns

  • email
  • ipv4
  • jwt
  • bearer_token
  • api_key
  • url_token
  • credit_card_basic

Built-in sensitive keys

  • password
  • passwd
  • secret
  • token
  • access_token
  • refresh_token
  • api_key
  • authorization

Development

python3 -m venv .venv
. .venv/bin/activate
pip install -e . pytest ruff
pytest
ruff check .

Security note

This package is intended to reduce accidental leakage, not guarantee perfect anonymization. Always validate your own threat model and pattern coverage for production systems.

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

python_log_redactor-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

python_log_redactor-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file python_log_redactor-0.1.0.tar.gz.

File metadata

  • Download URL: python_log_redactor-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_log_redactor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8f936127b610ef369ba60cad8e15666e86c3255009006fad74e79d4b6757b00d
MD5 0ff7c06dcaabcd84608936bb8dde6670
BLAKE2b-256 2881d3f78a835c3c82871174f3ca3eceb294a27bbb72abc4552de65657cb13e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_log_redactor-0.1.0.tar.gz:

Publisher: publish.yml on morgan-young/log-redactor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_log_redactor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_log_redactor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c82532c1b63139fc4e6fb3b6725bf10ba6243af9847858b4267b8c039bec68a
MD5 971d22b0831dda379cccb21f4b37f088
BLAKE2b-256 4885e26fc70d28a11c2af6b121d1cae45569eb159e41a05de283ba92a9926f6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_log_redactor-0.1.0-py3-none-any.whl:

Publisher: publish.yml on morgan-young/log-redactor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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