Metadata-Version: 2.4
Name: python-log-redactor
Version: 0.1.0
Summary: Lightweight sensitive data redaction for accidental printing of sensitive Python strings, dicts, and logs.
Project-URL: Homepage, https://github.com/morgan-young/python-log-redactor
Author: Morgan Young
License: MIT
License-File: LICENSE
Keywords: logging,privacy,redaction,security
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
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 :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# log-redactor

[![CI](https://github.com/morgan-young/log-redactor/actions/workflows/ci.yml/badge.svg)](https://github.com/morgan-young/log-redactor/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/python-log-redactor.svg)](https://pypi.org/project/python-log-redactor/)
[![Python](https://img.shields.io/pypi/pyversions/python-log-redactor.svg)](https://pypi.org/project/python-log-redactor/)
[![License](https://img.shields.io/pypi/l/python-log-redactor.svg)](https://github.com/morgan-young/log-redactor/blob/main/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

```bash
pip install python-log-redactor
```

## Quick start

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

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

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