Skip to main content

Zero-config PII redaction for Python logging

Project description

HushLog

Zero-config PII redaction for Python logging.

PyPI version Python versions CI License: MIT

Features

  • Zero-config -- one call to hushlog.patch() and you're done
  • Non-invasive -- wraps existing formatters, no logger rewrites needed
  • Performant -- pre-compiled regex with heuristic early-exit checks
  • Type-safe -- fully typed with PEP 561 py.typed marker
  • Python 3.10+ -- supports Python 3.10 through 3.13

Installation

pip install hushlog

Or with uv:

uv add hushlog

Quick Start

import logging
import hushlog

# Configure logging FIRST, then patch
logging.basicConfig(level=logging.INFO)
hushlog.patch()

logger = logging.getLogger(__name__)

logger.info("User email: john@example.com")
# Output: User email: [EMAIL REDACTED]

logger.info("Card: 4111-1111-1111-1111")
# Output: Card: [CREDIT_CARD REDACTED]

logger.info("SSN: 123-45-6789")
# Output: SSN: [SSN REDACTED]

How It Works

HushLog wraps your existing logging formatters with a RedactingFormatter that scans the final formatted string for PII patterns. It never replaces loggers or handlers -- your existing logger.info() calls remain unchanged. All regex patterns are pre-compiled at import time with lightweight heuristic pre-checks to minimize overhead on the hot logging path.

What Gets Redacted

Pattern Example Output Notes
Email john@example.com [EMAIL REDACTED] RFC 5322 subset, @ heuristic pre-check
Credit Card 4111-1111-1111-1111 [CREDIT_CARD REDACTED] Luhn validated, supports spaces/dashes
SSN 123-45-6789 [SSN REDACTED] Dashed format only, invalid ranges excluded
Phone (555) 123-4567 [PHONE REDACTED] US NANP, multiple formats

Configuration

Disable specific built-in patterns or add custom ones:

from hushlog import Config

hushlog.patch(Config(
    disable_patterns=frozenset({"phone"}),
    custom_patterns={"internal_id": r"ID-[A-Z]{3}-[0-9]{6}"},
))

Note: The mask_style option for partial masking (e.g., j***@example.com) is planned for v0.2.0.

Teardown

Call unpatch() to remove HushLog's formatter wrappers and restore the original formatters. This is useful for testing or runtime toggling:

hushlog.unpatch()

Calling unpatch() without a prior patch() is safe (no-op). Calling patch() multiple times is also safe (idempotent).

Limitations

  • Only handlers present on the root logger at patch() time are wrapped. Handlers added later will not be redacted.
  • Named loggers with propagate=False and their own handlers bypass root-level redaction.
  • No structured log support yet (structlog/loguru integrations planned for v0.3.0).
  • Phone detection is US NANP only.

Planned

IPv4/IPv6 addresses, AWS keys, Stripe keys, GitHub tokens, JWT tokens, partial masking, and more. See the roadmap for details.

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

License

MIT -- see LICENSE for details.

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

hushlog-0.1.0rc1.tar.gz (61.0 kB view details)

Uploaded Source

Built Distribution

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

hushlog-0.1.0rc1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file hushlog-0.1.0rc1.tar.gz.

File metadata

  • Download URL: hushlog-0.1.0rc1.tar.gz
  • Upload date:
  • Size: 61.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hushlog-0.1.0rc1.tar.gz
Algorithm Hash digest
SHA256 4ea24f9c06fce2c9d7cb9a8e9c34a8427a45d8e093010d4e2ad0930f7d948288
MD5 7dfe761a39be30b310bbcdff34b49aab
BLAKE2b-256 473b609c5fa323a5e7804e72dc9ba34ade59ac994f10c09eae0f574f2eba810a

See more details on using hashes here.

Provenance

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

Publisher: release.yml on FelipeMorandini/hushlog

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

File details

Details for the file hushlog-0.1.0rc1-py3-none-any.whl.

File metadata

  • Download URL: hushlog-0.1.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hushlog-0.1.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b8f5a1ecfca9bf6b7af4342ed7023a5efd4d7d65e2fd297f8393a76464916e7
MD5 eebbad6f7c3d7ae25a48724cc3ed34e9
BLAKE2b-256 f7e38ba77b9adc30390078042b49bceed9182715bb54151045280e0b2c8b77f9

See more details on using hashes here.

Provenance

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

Publisher: release.yml on FelipeMorandini/hushlog

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