Skip to main content

pii-safe-logger for Python

CI PyPI

Dependency-free PII-safe structured logging and redaction utilities for Python. It is the Python member of the pii-safe-logger ecosystem and follows the same privacy-first behavior as the JavaScript package.

Created by Luis Aneuris Tavarez De Jesus.

Features

  • Redacts nested dictionaries, collections, exceptions, objects, and circular references.
  • Detects emails, phones, SSNs, Luhn-valid payment cards, JWTs, bearer tokens, and secrets.
  • Supports custom sensitive fields, regular-expression rules, and partial masks.
  • Emits structured JSON with child context and transaction IDs.
  • Integrates with Python's standard logging module.
  • Zero runtime dependencies and fully typed.

Installation

pip install pii-safe-logger

Quick start

from pii_safe_logger import create_pii_safe_logger

logger = create_pii_safe_logger(service="payments-service").with_transaction()
logger.info(
    "Payment created for luis@example.com",
    {
        "cardNumber": "4111111111111111",
        "amount": 250,
        "authorization": "Bearer abc.def.ghi",
    },
)

Redact without logging

from pii_safe_logger import redact

safe = redact({
    "email": "luis@example.com",
    "profile": {"phone": "+1 809 555 1234"},
})

Partial masking

from pii_safe_logger import FieldMask, RedactionOptions, redact

options = RedactionOptions(mask_fields=(
    FieldMask("cardNumber", preserve_first=6, preserve_last=4, replacement="******"),
))

redact({"cardNumber": "4111111111111111"}, options)
# {"cardNumber": "411111******1111"}

Standard logging integration

import logging
from pii_safe_logger import PiiRedactingFilter

handler = logging.StreamHandler()
handler.addFilter(PiiRedactingFilter())

logger = logging.getLogger("payments")
logger.addHandler(handler)
logger.info("Customer: %s", "luis@example.com")

Development

python3 -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
ruff check .
mypy src
pytest
python -m build
python -m twine check dist/*

Security

Pattern matching cannot guarantee detection of every business-specific secret. Treat this package as defense in depth, add your own sensitive fields, and avoid intentionally passing credentials to logs. See SECURITY.md.

License

MIT

Metadata

Release files for pii-safe-logger 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pii-safe-logger 0.1.0
File Size Uploaded
pii_safe_logger-0.1.0.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pii-safe-logger 0.1.0
File Interpreter ABI Platform
pii_safe_logger-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.0 kB

Release files / pii_safe_logger-0.1.0.tar.gz

Download URL pii_safe_logger-0.1.0.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5dbe7886ba980ce9d5db3e10e288cce1f9abaf17f4f86ec31e68fc55967c6ee7
BLAKE2b-256 checksum
How to use checksums
779b9c405bfc20282279a38c8db8479619895e6019929ca1d7fe32d62caeaa48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release files / pii_safe_logger-0.1.0-py3-none-any.whl

Download URL pii_safe_logger-0.1.0-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72959be138e586b7d680a5dd75fa1c252e3034847fe47f41a03e2db2393d3f1c
BLAKE2b-256 checksum
How to use checksums
dcbd143b1737feda0bf612acbdd9172de8710cf1de051ad1a0234d3403b5c1ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page