SafeStream-Redactor
Find and redact PII and secrets in text of any size, in constant memory, entirely offline.
SafeStream-Redactor streams a file through a fixed-size window, so a 100 GB log uses the same memory as a 1 KB one. In one pass it catches personal data (emails, cards, SSNs, phone numbers, IP addresses, names) and credentials (cloud keys, API tokens, JWTs, private keys, unknown high-entropy secrets). Everything outside a redacted span, line endings included, comes out byte for byte as it went in.
Use it as a command-line tool, a Python library, a local REST API, an MCP server for AI agents, a CI secret gate, or a local web playground.
Try it in your browser → The demo runs the real package in WebAssembly, so nothing you paste leaves your machine.
30-second quickstart
pip install safestream-redactor
$ printf 'user=bob@corp.example ssn: 123-45-6789 key=AKIAIOSFODNN7EXAMPLE\n' | safestream redact - -o -
user=[REDACTED] ssn: [REDACTED] key=[REDACTED]
Python 3.10+ on Linux, macOS or Windows. The base install has no third-party runtime dependencies.
Why SafeStream
- Constant memory. Text is processed in chunks with an overlapping window, so an entity cut by a chunk boundary is still caught whole, and memory never grows with input size. A test redacts a generated 1 GB file with peak Python allocations under 16 MiB.
- PII and secrets together. Most PII tools focus on personal data. SafeStream also detects AWS, GitHub, Slack, Stripe, Google, OpenAI and Anthropic keys, JWTs, private-key blocks, credentials in URLs, and undocumented secrets by entropy.
- Offline by design. While it runs, outbound network connections are blocked in process (on Linux, optionally by the kernel). The REST API, MCP server and web UI bind to loopback only, and nothing ever logs the matched values.
- Deterministic. Single-core, multi-core and native (Rust) runs produce byte-identical output, and every redaction mode is a pure function of the value, so equal inputs always redact the same way.
Choose your path
| I want to… | Use | Go to |
|---|---|---|
| Sanitize files, directories or pipes | CLI | CLI |
| Redact inside my own application | Python library | Python |
| Call it from another language or a container | REST API | REST API |
| Give an AI agent a safe redaction tool | MCP server | MCP server |
| Try it without installing anything | Live demo | Open the demo |
| Try it on my own large files, without code | Local web playground | Web playground |
| Block secrets before they are committed or merged | Pre-commit hook, GitHub Action | CI gate |
| Run it fully isolated | Docker | Docker |
Quickstarts
The examples below use this small log. Every command and output in this README is run by the test suite, so what you see is what you get.
$ printf '%s\n' 'login ok user=maria.garcia@corpmail.com ip=10.20.30.40' 'payment card=4111 1111 1111 1111 ssn=123-45-6789' 'deploy aws_key=AKIAIOSFODNN7EXAMPLE token=ghp_1234567890abcdefghijklmnopqrstuvwxyz' > app.log
CLI
$ safestream redact app.log -o -
login ok user=[REDACTED] ip=[REDACTED]
payment card=[REDACTED] ssn=[REDACTED]
deploy aws_key=[REDACTED] token=[REDACTED]
$ safestream detect app.log
app.log:1:15: email conf=0.95
app.log:1:44: ipv4 conf=1.00
app.log:2:14: credit_card conf=1.00
app.log:2:38: ssn conf=1.00
app.log:3:16: aws_key conf=0.98
app.log:3:43: github_token conf=0.98
-- 6 detection(s) (matched text hidden; --show-text reveals it)
$ safestream redact app.log -o - --types email,ssn --mode mask --keep-last 4
login ok user=*********************.com ip=10.20.30.40
payment card=4111 1111 1111 1111 ssn=*******6789
deploy aws_key=AKIAIOSFODNN7EXAMPLE token=ghp_1234567890abcdefghijklmnopqrstuvwxyz
detect never prints the matched values unless you pass --show-text, so its output is
safe to keep in logs. More things to try:
safestream redact app.log -o clean.log --mode pseudonymize --hmac-key "$KEY" # stable <EMAIL_…> tokens
safestream redact logs/ -o logs_clean/ --workers 8 # a directory tree, in parallel
safestream redact huge.log -o clean.log --workers 8 # one big file, split across cores
tail -f app.log | safestream redact - -o - # a live stream
safestream redact app.log -o clean.log --stats --report run.json # counts only, never values
safestream init-config -o policy.toml # a documented policy file to edit
Every option, redaction mode and exit code: docs/CLI.md.
Python
from safestream_redactor import EntityType, RedactionPolicy, Redactor
redactor = Redactor()
redactor.redact("email bob@corp.io, ssn: 123-45-6789") # -> 'email [REDACTED], ssn: [REDACTED]'
# detect without redacting; your code gets the matched text, logs never do
[(d.entity_type.value, d.text) for d in redactor.detect("mail bob@corp.io from 10.0.0.1")]
# -> [('email', 'bob@corp.io'), ('ipv4', '10.0.0.1')]
# choose the types, and how each one is rewritten
policy = RedactionPolicy(replacements={EntityType.EMAIL: "<EMAIL>"})
Redactor(types=["email"], policy=policy).redact("bob@corp.io 123-45-6789")
# -> '<EMAIL> 123-45-6789'
# file to file in constant memory; the output appears atomically, never half-written
stats = redactor.redact_file("app.log", "app.clean.log")
stats.summary() # -> '6 detection(s): aws_key=1, credit_card=1, email=1, github_token=1, ipv4=1, ssn=1'
# any iterable of text chunks: a file object, a socket reader, a generator
with open("app.log", newline="") as source:
for piece in redactor.redact_stream(source):
print(piece, end="")
REST API
A standard-library HTTP server around the same engine. It binds to 127.0.0.1 and never
logs request bodies.
safestream serve # http://127.0.0.1:8000
curl -s -X POST http://127.0.0.1:8000/redact \
-H 'Content-Type: application/json' \
-d '{"text": "email bob@corp.io key AKIAIOSFODNN7EXAMPLE"}'
# {"redacted": "email [REDACTED] key [REDACTED]", "total_detections": 2, "detections_by_type": {"aws_key": 1, "email": 1}}
POST /scan returns types and offsets only, never the matched text. There are also
GET /health, /version and /detectors. See docs/rest-api.md.
MCP server
safestream mcp-serve gives an AI agent scan, redact, explain_detection,
detectors and health tools over stdio. Add it to your MCP client's configuration:
{
"mcpServers": {
"safestream": { "command": "safestream", "args": ["mcp-serve"] }
}
}
scan tells the agent what and where, never the secret itself. For
deploy key AKIAIOSFODNN7EXAMPLE it returns:
{"count": 1, "findings": [{"type": "aws_key", "start": 11, "end": 31, "length": 20, "confidence": 0.98, "severity": "critical", "detector": "deterministic", "redacted": true}]}
See docs/MCP.md.
Web playground
The live demo needs no install. It covers the playground (every
redaction mode the pure-Python engine runs, a policy.toml editor, and the matching CLI,
Python, REST and MCP calls), the streaming inspector, the REST and MCP consoles, and the CI
gate, for inputs up to 1 MiB. For big files, run the playground locally:
pip install 'safestream-redactor[ui]'
safestream ui # opens http://127.0.0.1:8501
Paste text or upload a file to see findings highlighted by severity, the original and redacted text side by side, and a step-by-step replay of the streaming engine. It is served on loopback only, with telemetry off and the network guard on.
See docs/WEB_UI.md.
CI gate
safestream detect PATHS --fail-on-detect exits with status 1 when it finds anything. It
reports file:line:col and the type, never the secret. As a pre-commit hook:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/MounishSenisetty/SafeStream-Redactor
rev: v1.0.0
hooks:
- id: safestream-detect
As a GitHub Action, with an optional SARIF report for code scanning:
- uses: MounishSenisetty/SafeStream-Redactor@v1.0.0
with:
paths: "."
sarif-file: results.sarif
See docs/CI_CD.md.
Docker
Multi-architecture images (amd64, arm64) with an SBOM and provenance are published to GitHub Container Registry. Run with no network at all:
docker run --rm --network none --user "$(id -u):$(id -g)" -v "$PWD":/data \
ghcr.io/mounishsenisetty/safestream-redactor redact /data/app.log -o /data/clean.log
docker-compose.yml
adds a read-only filesystem, no capabilities and a 64 MiB memory cap.
Install options
| Install | Adds |
|---|---|
pip install safestream-redactor |
Everything above except the extras below. No runtime dependencies. |
pip install 'git+https://github.com/MounishSenisetty/SafeStream-Redactor#subdirectory=native' |
The optional Rust core: 3–12× faster, byte-identical output. Not on PyPI; this builds it from source and needs a Rust toolchain. Enable with --backend native. |
pip install 'safestream-redactor[ui]' |
The web playground (Streamlit). |
pip install 'safestream-redactor[crypto]' |
Reversible --mode encrypt (AES-256-GCM) and safestream deanonymize. |
pip install 'safestream-redactor[all]' |
ui and crypto together. |
pip install 'safestream-redactor[ner]' |
spaCy names, organisations and locations (--ner). Then run python -m spacy download en_core_web_sm. |
pip install 'safestream-redactor[onnx]' |
An on-device ONNX NER model you supply (--onnx); see docs/DETECTORS.md. |
Only need the command? pipx install safestream-redactor, or run it without installing:
uvx safestream-redactor --help.
What it detects
| Category | Entity types |
|---|---|
| Personal data | email, phone, credit_card, ssn, ipv4, ipv6, mac_address, address, dob, username |
| Labelled identifiers | id_number: account, patient, MRN, passport, policy and case numbers after their label |
| Cloud and service credentials | aws_key, aws_secret, aws_account_id, github_token, slack_token, slack_webhook, stripe_key, google_api_key, sendgrid_key, twilio_key, npm_token, openai_key, anthropic_key, vendor_token |
| Other secrets | api_key, jwt, private_key, url_credentials, password_hash, secret (high entropy, no known format) |
Names (with [ner] or [onnx]) |
person, org, loc |
| Opt-in | date (--dates), url (--types url), regional IDs with --regional: iban, crypto_address, uk_nino, nhs_number, in_aadhaar, in_pan |
| Your own | custom, from --custom-word and --custom-regex |
Card, IBAN, NHS and Aadhaar numbers are checksum-validated. Matches identified by
shape alone (a bare SSN, phone number, email or IP) score lower next to words like
example or test, so documentation snippets are not redacted.
How it works
text chunks ──> [ rolling buffer: chunk + 8 KiB overlap ] ──> redacted chunks
│
┌────────────────────────┼─────────────────────────┐
▼ ▼ ▼
patterns + validators entropy scoring NER (optional)
(Luhn, SSN rules, …) for unknown secrets spaCy or ONNX
└────────────────────────┼─────────────────────────┘
▼
contextual scoring ─> confidence filter ─> overlap resolution
▼
redaction policy: replace, mask, pseudonymize, hash, encrypt, fictionalize
Only text at least one overlap (8 KiB by default) from the end of the buffer is written each round. The rest is carried into the next round, so an entity up to that length is always seen whole, even when a chunk boundary cuts through it. If an output boundary would split a detection, it moves back to the detection's start. Architecture details: SYSTEM_DESIGN.md.
Performance and accuracy
- Throughput: about 1.1–1.4 MB/s per core in pure Python and 3–17 MB/s with the native
core, on the evaluation corpora in power-saving mode on one thread.
--workers Nscales across cores. - Against Presidio's pattern recognizers: higher precision on every corpus and 24–169× faster per core. Character F1 is higher on secrets and RedactionBench, level on presidio-research, and lower on ai4privacy with default settings.
- Where it loses: Presidio's transformer engine redacts more entities fully, and wins on ai4privacy. SafeStream misses values inside structured fields, unlabelled ID numbers, many international phone formats, and many names.
Full tables, confidence intervals and conditions: docs/EVALUATION.md.
Limitations
No tool can guarantee every name or free-form identifier in prose is found: "April" is a
name and a month, and an account number looks like any other run of digits. SafeStream is
tuned for high precision on structured PII and credentials. For names, enable [ner] or
[onnx]. For identifiers without a fixed format, add label-anchored patterns, as in
examples/policy.toml.
Review redacted output before sharing it anywhere a miss would be costly.
Security
The in-process network guard is defence in depth, not a sandbox: native code or a child
process can bypass it. On Linux, --offline-hard seccomp or --offline-hard netns adds a
kernel-enforced block, and docker run --network none isolates the whole container. The
threat model and how to report a vulnerability are in
SECURITY.md.
Documentation
| Topic | Page |
|---|---|
| Every CLI option, policy files, plugins, network isolation | docs/CLI.md |
| Detection tiers and how to extend them | docs/DETECTORS.md |
| A guided tour of every feature | docs/DEMO.md |
| Memory budgets and constant-memory guarantees | docs/MEMORY_ARCHITECTURE.md |
| The native core | docs/NATIVE_CORE.md |
Linux file-system DLP (safestream fanotify) |
docs/FANOTIFY.md |
| Evaluation results | docs/EVALUATION.md |
| Changelog | CHANGELOG.md |
Contributing
git clone https://github.com/MounishSenisetty/SafeStream-Redactor
cd SafeStream-Redactor
pip install -e '.[dev]'
pytest
See CONTRIBUTING.md and the good first issues.
License
Metadata
Release files for safestream-redactor 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| safestream_redactor-1.0.0.tar.gz | 182.8 kB | With provenance | Details for safestream_redactor-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| safestream_redactor-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for safestream_redactor-1.0.0-py3-none-any.whl |
Total release size: 390.3 kB
Release files / safestream_redactor-1.0.0.tar.gz
| Download URL | safestream_redactor-1.0.0.tar.gz |
|---|---|
| Size | 182.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba1d33a28b0836590b4c481cbd2684dadefa012fb77d2701994fe2d38519ad2d
|
|
BLAKE2b-256 checksum How to use checksums |
bf9438f21474c2eae3992abaf4fe98d6819e8d5868837bce9872a5c5ae9ac8c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 14, 2026.
Transparency logRelease files / safestream_redactor-1.0.0-py3-none-any.whl
| Download URL | safestream_redactor-1.0.0-py3-none-any.whl |
|---|---|
| Size | 207.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c33b72be57d095e74d4410b54a0a615d0e2d2db9a54df3fd05a0516bad2efa3
|
|
BLAKE2b-256 checksum How to use checksums |
86ecce8813aa024adcbac7d0b428c5a94d76603ea5f883b517d50b91a33b6698
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 14, 2026.
Transparency logSecurity for safestream-redactor 1.0.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for safestream_redactor-1.0.0.tar.gz
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 Nov 14, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.