Metadata-Version: 2.4
Name: philiprehberger-masked-print
Version: 0.1.6
Summary: Automatically mask sensitive values (API keys, passwords, tokens) in logs and print output
Project-URL: Homepage, https://github.com/philiprehberger/py-masked-print#readme
Project-URL: Repository, https://github.com/philiprehberger/py-masked-print
Project-URL: Issues, https://github.com/philiprehberger/py-masked-print/issues
Project-URL: Changelog, https://github.com/philiprehberger/py-masked-print/blob/main/CHANGELOG.md
Author: Philip Rehberger
License-Expression: MIT
License-File: LICENSE
Keywords: logging,mask,redact,secrets,security,sensitive
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.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# philiprehberger-masked-print

[![Tests](https://github.com/philiprehberger/py-masked-print/actions/workflows/publish.yml/badge.svg)](https://github.com/philiprehberger/py-masked-print/actions/workflows/publish.yml)
[![PyPI version](https://img.shields.io/pypi/v/philiprehberger-masked-print.svg)](https://pypi.org/project/philiprehberger-masked-print/)
[![License](https://img.shields.io/github/license/philiprehberger/py-masked-print)](LICENSE)

Automatically mask sensitive values (API keys, passwords, tokens) in logs and print output.

## Installation

```bash
pip install philiprehberger-masked-print
```

## Usage

```python
from philiprehberger_masked_print import mask, mask_dict, MaskedFormatter

# Mask a single string
masked = mask("sk-abc123secret456xyz")
# "sk-a*************xyz"
```

### Mask dictionaries

```python
config = {
    "host": "localhost",
    "password": "super-secret-value",
    "database": {
        "connection_string": "postgres://admin:pass@localhost/db",
    },
}

safe = mask_dict(config)
# {
#     "host": "localhost",
#     "password": "supe***********lue",
#     "database": {
#         "connection_string": "post*****************/db",
#     },
# }
```

### Auto-mask log output

```python
import logging
from philiprehberger_masked_print import MaskedFormatter

handler = logging.StreamHandler()
handler.setFormatter(MaskedFormatter("%(levelname)s: %(message)s"))

logger = logging.getLogger("app")
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

logger.info("Using key sk-proj-abc123def456ghi789jkl012mno")
# INFO: Using key sk-p*************************mno
```

## API

| Function / Class | Description |
|---|---|
| `mask(value, *, show_first=4, show_last=3, mask_char="*")` | Mask a string, keeping the first and last N characters visible |
| `mask_dict(data, *, sensitive_keys=None, show_first=4, show_last=3)` | Recursively mask sensitive key values in a dictionary |
| `MaskedFormatter(fmt)` | Logging formatter that auto-redacts secret patterns (sk-..., eyJ..., AKIA..., URL credentials) |


## Development

```bash
pip install -e .
python -m pytest tests/ -v
```

## License

MIT
