Lightweight sensitive data redaction for accidental printing of sensitive Python strings, dicts, and logs.
Project description
log-redactor
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/tuplestructures - Works with standard library
loggingand%s-style args - Keeps runtime dependencies at zero (stdlib only)
Installation
pip install python-log-redactor
Quick start
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
from log_redactor import RedactingFilter, redact, redact_dict
redact(text: str, patterns=None, custom_patterns=None, replacement="[REDACTED]") -> strredact_dict(data: dict, keys=None, patterns=None, custom_patterns=None, replacement="[REDACTED]") -> dictRedactingFilter(logging.Filter)
Built-in patterns
emailipv4jwtbearer_tokenapi_keyurl_tokencredit_card_basic
Built-in sensitive keys
passwordpasswdsecrettokenaccess_tokenrefresh_tokenapi_keyauthorization
Development
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_log_redactor-0.1.0.tar.gz.
File metadata
- Download URL: python_log_redactor-0.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f936127b610ef369ba60cad8e15666e86c3255009006fad74e79d4b6757b00d
|
|
| MD5 |
0ff7c06dcaabcd84608936bb8dde6670
|
|
| BLAKE2b-256 |
2881d3f78a835c3c82871174f3ca3eceb294a27bbb72abc4552de65657cb13e6
|
Provenance
The following attestation bundles were made for python_log_redactor-0.1.0.tar.gz:
Publisher:
publish.yml on morgan-young/log-redactor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_log_redactor-0.1.0.tar.gz -
Subject digest:
8f936127b610ef369ba60cad8e15666e86c3255009006fad74e79d4b6757b00d - Sigstore transparency entry: 1596120987
- Sigstore integration time:
-
Permalink:
morgan-young/log-redactor@56641a2d0c0e0e5a5842811067e92ce0d780d3d7 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/morgan-young
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@56641a2d0c0e0e5a5842811067e92ce0d780d3d7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file python_log_redactor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_log_redactor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c82532c1b63139fc4e6fb3b6725bf10ba6243af9847858b4267b8c039bec68a
|
|
| MD5 |
971d22b0831dda379cccb21f4b37f088
|
|
| BLAKE2b-256 |
4885e26fc70d28a11c2af6b121d1cae45569eb159e41a05de283ba92a9926f6d
|
Provenance
The following attestation bundles were made for python_log_redactor-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on morgan-young/log-redactor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_log_redactor-0.1.0-py3-none-any.whl -
Subject digest:
8c82532c1b63139fc4e6fb3b6725bf10ba6243af9847858b4267b8c039bec68a - Sigstore transparency entry: 1596121058
- Sigstore integration time:
-
Permalink:
morgan-young/log-redactor@56641a2d0c0e0e5a5842811067e92ce0d780d3d7 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/morgan-young
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@56641a2d0c0e0e5a5842811067e92ce0d780d3d7 -
Trigger Event:
push
-
Statement type: