Metadata-Version: 2.5
Name: pii-safe-logger
Version: 0.1.0
Summary: PII-safe structured logging and redaction utilities for Python.
Project-URL: Homepage, https://www.ltavarez.me/
Project-URL: Documentation, https://github.com/uppy19d0/pii-safe-logger-python#readme
Project-URL: Repository, https://github.com/uppy19d0/pii-safe-logger-python
Project-URL: Issues, https://github.com/uppy19d0/pii-safe-logger-python/issues
Project-URL: Changelog, https://github.com/uppy19d0/pii-safe-logger-python/blob/main/CHANGELOG.md
Author: Luis Aneuris Tavarez De Jesus
License-Expression: MIT
License-File: LICENSE
Keywords: logger,logging,pii,privacy,redaction,security
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: System :: Logging
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: mypy>=1.11; extra == 'dev'
Requires-Dist: pytest-cov>=6.0; extra == 'dev'
Requires-Dist: pytest>=8.3; extra == 'dev'
Requires-Dist: ruff>=0.9; extra == 'dev'
Requires-Dist: twine>=6.0; extra == 'dev'
Description-Content-Type: text/markdown

# pii-safe-logger for Python

[![CI](https://github.com/uppy19d0/pii-safe-logger-python/actions/workflows/ci.yml/badge.svg)](https://github.com/uppy19d0/pii-safe-logger-python/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/pii-safe-logger.svg)](https://pypi.org/project/pii-safe-logger/)

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](https://www.ltavarez.me/).

## 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

```bash
pip install pii-safe-logger
```

## Quick start

```python
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

```python
from pii_safe_logger import redact

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

## Partial masking

```python
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

```python
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

```bash
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](SECURITY.md).

## License

MIT

