@privacyscrubber/sdk 2.4.0 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/benchmark.js +33 -25
  2. package/browser.js +274 -37
  3. package/cli.js +7 -1
  4. package/examples/python-bridge/bridge_daemon.cjs +2 -2
  5. package/examples/python-bridge/fastapi_example.py +1 -1
  6. package/examples/python-bridge/privacyscrubber/__init__.py +1 -1
  7. package/examples/python-bridge/privacyscrubber/bridge_daemon.cjs +1 -1
  8. package/examples/python-bridge/privacyscrubber/cli.py +1 -1
  9. package/examples/python-bridge/privacyscrubber/client.py +11 -5
  10. package/examples/python-bridge/pyproject.toml +1 -1
  11. package/examples/python-bridge/setup.py +1 -1
  12. package/examples/python-bridge/test_python_bridge.py +1 -1
  13. package/fastmcp.cjs +29 -18
  14. package/index.cjs +31 -13
  15. package/index.js +35 -17
  16. package/package.json +5 -1
  17. package/ps-license-manager.js +261 -11
  18. package/ps-pii-engine.cjs +3611 -8
  19. package/scrubber-core.cjs +1801 -8
  20. package/vercel-ai.cjs +1 -1
  21. package/vercel-ai.js +1 -1
  22. package/examples/python-bridge/dist/privacyscrubber-2.3.9-py3-none-any.whl +0 -0
  23. package/examples/python-bridge/dist/privacyscrubber-2.3.9.tar.gz +0 -0
  24. package/examples/python-bridge/privacyscrubber.egg-info/PKG-INFO +0 -311
  25. package/examples/python-bridge/privacyscrubber.egg-info/SOURCES.txt +0 -18
  26. package/examples/python-bridge/privacyscrubber.egg-info/dependency_links.txt +0 -1
  27. package/examples/python-bridge/privacyscrubber.egg-info/entry_points.txt +0 -3
  28. package/examples/python-bridge/privacyscrubber.egg-info/requires.txt +0 -18
  29. package/examples/python-bridge/privacyscrubber.egg-info/top_level.txt +0 -1
package/vercel-ai.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @privacyscrubber/sdk/vercel-ai
3
3
  * Zero-Trust Data Sanitization (ZTDS) In-Memory Middleware for Vercel AI SDK
4
- * Conforms to IETF Standards Track: draft-sibiryakov-ztds-protocol-02
4
+ * Conforms to IETF Standards Track: draft-sibiryakov-ztds-protocol-01
5
5
  *
6
6
  * Core Protocol Invariants:
7
7
  * 1. Zero External Egress Prior to Sanitization
package/vercel-ai.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @privacyscrubber/sdk/vercel-ai
3
3
  * Zero-Trust Data Sanitization (ZTDS) In-Memory Middleware for Vercel AI SDK
4
- * Conforms to IETF Standards Track: draft-sibiryakov-ztds-protocol-02
4
+ * Conforms to IETF Standards Track: draft-sibiryakov-ztds-protocol-01
5
5
  *
6
6
  * Sub-millisecond in-memory prompt sanitization and real-time streaming de-tokenization.
7
7
  * Compatible with Vercel AI SDK v3/v4: streamText, generateText, wrapLanguageModel.
@@ -1,311 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: privacyscrubber
3
- Version: 2.4.0
4
- Summary: Zero-Trust Data Sanitization & In-Memory PII Shield for Python AI Pipelines (ZTDS RFC v1.0)
5
- Home-page: https://privacyscrubber.com
6
- Author: Ilya Sibiryakov (BrandMeWeb)
7
- Author-email: "Ilya Sibiryakov (BrandMeWeb)" <contact@privacyscrubber.com>
8
- License: Commercial / Proprietary
9
- Project-URL: Homepage, https://privacyscrubber.com
10
- Project-URL: Documentation, https://privacyscrubber.com/sdk/
11
- Project-URL: Repository, https://github.com/moxno/privacyscrubber-mcp
12
- Project-URL: Standard, https://datatracker.ietf.org/doc/draft-sibiryakov-ztds-protocol/
13
- Keywords: pii,redaction,sanitization,zero-trust,ztds,langchain,fastapi,presidio,llm-security,gdpr,hipaa,ai-guardrail
14
- Classifier: Development Status :: 5 - Production/Stable
15
- Classifier: Intended Audience :: Developers
16
- Classifier: Intended Audience :: Information Technology
17
- Classifier: Topic :: Security
18
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
- Classifier: Programming Language :: Python :: 3
20
- Classifier: Programming Language :: Python :: 3.8
21
- Classifier: Programming Language :: Python :: 3.9
22
- Classifier: Programming Language :: Python :: 3.10
23
- Classifier: Programming Language :: Python :: 3.11
24
- Classifier: Programming Language :: Python :: 3.12
25
- Classifier: Programming Language :: Python :: 3.13
26
- Classifier: Operating System :: OS Independent
27
- Requires-Python: >=3.8
28
- Description-Content-Type: text/markdown
29
- Provides-Extra: fastapi
30
- Requires-Dist: fastapi>=0.100.0; extra == "fastapi"
31
- Requires-Dist: uvicorn>=0.20.0; extra == "fastapi"
32
- Requires-Dist: pydantic>=2.0.0; extra == "fastapi"
33
- Provides-Extra: langchain
34
- Requires-Dist: langchain-core>=0.1.0; extra == "langchain"
35
- Provides-Extra: llamaindex
36
- Requires-Dist: llama-index-core>=0.10.0; extra == "llamaindex"
37
- Provides-Extra: all
38
- Requires-Dist: fastapi>=0.100.0; extra == "all"
39
- Requires-Dist: uvicorn>=0.20.0; extra == "all"
40
- Requires-Dist: pydantic>=2.0.0; extra == "all"
41
- Requires-Dist: langchain-core>=0.1.0; extra == "all"
42
- Requires-Dist: llama-index-core>=0.10.0; extra == "all"
43
- Dynamic: author
44
- Dynamic: home-page
45
- Dynamic: requires-python
46
-
47
- # PrivacyScrubber Python Bridge (ZTDS Zero-Egress Sidecar)
48
-
49
- Sub-millisecond, zero-dependency Python adapter for **PrivacyScrubber SDK** (`@privacyscrubber/sdk`).
50
-
51
- Enforces **Zero-Trust Data Sanitization (ZTDS RFC v1.0)** across Python AI and data pipelines:
52
- - **FastAPI / Flask / Django**: Pre-LLM sanitization and post-LLM in-memory rehydration.
53
- - **LangChain**: `ZTDSCallbackHandler` and `ZTDSDocumentTransformer`.
54
- - **LlamaIndex**: Pre-embedding chunk and metadata sanitization.
55
- - **Raw OpenAI / Anthropic / Gemini SDKs**: Direct string and dictionary tokenization.
56
-
57
- ---
58
-
59
- ## Architectural Comparison: PrivacyScrubber vs. Microsoft Presidio
60
-
61
- | Metric | Microsoft Presidio | PrivacyScrubber ZTDS Bridge |
62
- | :--- | :--- | :--- |
63
- | **Inference Latency** | ~35ms – 65ms per request | **~0.15ms – 0.40ms per request (<1ms SLA)** |
64
- | **Memory Footprint** | 1.8 GB – 3.2 GB RAM (PyTorch / spaCy) | **< 25 MB RAM (Zero PyTorch / zero spaCy)** |
65
- | **Python Dependencies** | `presidio-analyzer`, `presidio-anonymizer`, `spacy`, `torch` | **0 Dependencies (Python Standard Library Only)** |
66
- | **Round-Trip Re-hydration** | Non-trivial (custom hash table mapping required) | **Native 100% Round-Trip (`client.restore()`)** |
67
- | **Pre-Configured Profiles** | Basic PII only (requires custom YAML recognizers) | **30 Built-in Industry Profiles (HIPAA, Financial, Legal, HR, etc.)** |
68
- | **Network Egress** | Potential telemetry unless air-gapped | **0.00 Bytes Network Egress (RAM-only volatile mapping)** |
69
- | **Container Startup** | 15 – 30 seconds model loading time | **< 100 milliseconds** |
70
-
71
- ---
72
-
73
- ---
74
-
75
- ## Installation & Prerequisites
76
-
77
- 1. Ensure **Node.js** (v18+) and **Python** (3.8+) are available on your system.
78
- 2. Install `@privacyscrubber/sdk`:
79
- ```bash
80
- npm install @privacyscrubber/sdk
81
- ```
82
- 3. Install the Python package via `pip`:
83
- ```bash
84
- # Editable local development:
85
- pip install -e npm-sdk/examples/python-bridge
86
-
87
- # Or standard pip install:
88
- pip install ./npm-sdk/examples/python-bridge
89
- ```
90
- *Note: Zero external Python dependencies are required.*
91
-
92
- ---
93
-
94
- ## Command Line Interface (CLI)
95
-
96
- The package bundles a terminal CLI utility `privacyscrubber` (alias: `ps-bridge`):
97
-
98
- ```bash
99
- # Check ZTDS engine status and uptime
100
- privacyscrubber ping
101
- privacyscrubber status
102
-
103
- # Sanitize text directly
104
- privacyscrubber sanitize "Customer Alice Cooper (alice@hospital.org)" --profile Healthcare
105
-
106
- # Pipe text through standard input:
107
- echo "Analyze wire for John Doe john@corp.com" | privacyscrubber sanitize
108
-
109
- # Output structured JSON with tokens and compliance telemetry:
110
- privacyscrubber sanitize "Patient John Doe" --json
111
-
112
- # Restore surrogate tokens:
113
- privacyscrubber restore "Patient [NAME_1]" --token-map '{"[NAME_1]": "John Doe"}'
114
- ```
115
-
116
- ---
117
-
118
- ## Quickstart
119
-
120
- ### 1. Synchronous Client
121
-
122
- ```python
123
- from privacyscrubber import PrivacyScrubber
124
-
125
- # Initialize sidecar in local RAM (auto-starts daemon)
126
- with PrivacyScrubber(default_profile="General") as ps:
127
- # Sanitize prompt before sending to cloud LLM
128
- result = ps.sanitize("Please review intake for patient John Doe (john@acme.com, phone +1-555-0199).")
129
-
130
- print("Sanitized Prompt:", result.sanitized)
131
- # Output: Please review intake for patient [NAME_1] ([EMAIL_1], phone [PHONE_1]).
132
-
133
- # Simulate LLM operating strictly on tokens
134
- ai_response = "I have noted records for [NAME_1] ([EMAIL_1])."
135
-
136
- # Restore cleartext tokens in local RAM
137
- restored = ps.restore(ai_response)
138
- print("Restored Answer:", restored.restored_text)
139
- # Output: I have noted records for John Doe (john@acme.com).
140
- ```
141
-
142
- ### 2. Asynchronous Client (FastAPI / asyncio)
143
-
144
- ```python
145
- import asyncio
146
- from privacyscrubber import AsyncPrivacyScrubber
147
-
148
- async def main():
149
- async with AsyncPrivacyScrubber(default_profile="Healthcare") as ps:
150
- res = await ps.sanitize("Patient Alice Cooper (DOB: 1984-05-12, SSN: 000-11-2222).")
151
- print("Sanitized:", res.sanitized)
152
- # Patient [NAME_1] (DOB: [DATE_1], SSN: [ID_1]).
153
-
154
- restored = await ps.restore("Prescription confirmed for [NAME_1].")
155
- print("Restored:", restored.restored_text)
156
-
157
- asyncio.run(main())
158
- ```
159
-
160
- ---
161
-
162
- ## Framework Integrations
163
-
164
- ### FastAPI Zero-Egress Proxy (`fastapi_example.py`)
165
-
166
- Run an OpenAI-compatible proxy that guarantees no raw PII ever touches OpenAI or external model APIs:
167
-
168
- ```python
169
- from fastapi import FastAPI
170
- from privacyscrubber import AsyncPrivacyScrubber
171
-
172
- app = FastAPI()
173
- scrubber = AsyncPrivacyScrubber()
174
-
175
- @app.on_event("startup")
176
- async def on_startup():
177
- await scrubber.start()
178
-
179
- @app.on_event("shutdown")
180
- async def on_shutdown():
181
- await scrubber.close()
182
-
183
- @app.post("/v1/chat/completions")
184
- async def chat_proxy(payload: dict):
185
- # 1. Sanitize user prompt in client memory (<0.2ms)
186
- messages = payload.get("messages", [])
187
- user_prompt = messages[-1]["content"]
188
-
189
- sanitized = await scrubber.sanitize(user_prompt)
190
- messages[-1]["content"] = sanitized.sanitized
191
-
192
- # 2. Forward sanitized payload to cloud LLM (httpx call)
193
- # raw_llm_response = await client.post("https://api.openai.com/v1/chat/completions", json=payload)
194
- mock_llm_reply = f"Acknowledged request for {sanitized.sanitized}"
195
-
196
- # 3. Restore cleartext in RAM before returning to end-user
197
- restored = await scrubber.restore(mock_llm_reply, token_map=sanitized.token_map)
198
- return {"choices": [{"message": {"role": "assistant", "content": restored.restored_text}}]}
199
- ```
200
-
201
- ### LangChain (`langchain_adapter.py`)
202
-
203
- #### Callback Handler (Transparent Pre/Post LLM Guard)
204
- ```python
205
- from langchain_openai import ChatOpenAI
206
- from langchain_adapter import ZTDSCallbackHandler
207
-
208
- llm = ChatOpenAI(
209
- model="gpt-4o",
210
- callbacks=[ZTDSCallbackHandler(profile="Financial")]
211
- )
212
-
213
- # Prompts are automatically sanitized before leaving process memory;
214
- # LLM outputs are automatically restored before returning to your code.
215
- response = llm.invoke("What is the credit rating for customer David Miller (SSN 987-65-4321)?")
216
- print(response.content)
217
- ```
218
-
219
- #### Vector Ingestion Guard (Pinecone, Chroma, Qdrant)
220
- ```python
221
- from langchain_adapter import ZTDSDocumentTransformer
222
-
223
- transformer = ZTDSDocumentTransformer(
224
- profile="Financial",
225
- sensitive_metadata_keys=["customer_email", "account_id"]
226
- )
227
-
228
- # Sanitizes both page_content and sensitive metadata dictionaries
229
- safe_docs = transformer.transform_documents(raw_docs)
230
- vector_store.add_documents(safe_docs)
231
- ```
232
-
233
- ---
234
-
235
- ## Nested Dictionary & JSON Sanitization
236
-
237
- Sanitize complex structured payloads (REST API payloads, MongoDB documents, JSON logs):
238
-
239
- ```python
240
- payload = {
241
- "user_id": 9012,
242
- "customer": {
243
- "name": "Sarah Connor",
244
- "email": "sconnor@cyberdyne.org",
245
- "phones": ["+1-555-0199", "+1-555-0188"]
246
- },
247
- "status": "active"
248
- }
249
-
250
- # Recursively sanitizes strings, preserving keys and types intact:
251
- result = ps.sanitize_object(payload)
252
- print(result.sanitized)
253
- # {
254
- # "user_id": 9012,
255
- # "customer": {
256
- # "name": "[NAME_1]",
257
- # "email": "[EMAIL_1]",
258
- # "phones": ["[PHONE_1]", "[PHONE_2]"]
259
- # },
260
- # "status": "active"
261
- # }
262
-
263
- # Restore structure:
264
- restored = ps.restore_object(result.sanitized, token_map=result.token_map)
265
- ```
266
-
267
- ---
268
-
269
- ## Production Docker Deployment
270
-
271
- Deploying Python applications alongside the PrivacyScrubber sidecar in a single multi-runtime container:
272
-
273
- ```dockerfile
274
- FROM node:22-bookworm-slim AS node-base
275
-
276
- FROM python:3.11-slim-bookworm
277
-
278
- # Copy Node.js runtime into Python container
279
- COPY --from=node-base /usr/local/bin/node /usr/local/bin/node
280
- COPY --from=node-base /usr/local/lib/node_modules /usr/local/lib/node_modules
281
-
282
- WORKDIR /app
283
-
284
- # Install SDK bridge
285
- COPY package*.json ./
286
- RUN npm install @privacyscrubber/sdk --production
287
-
288
- # Install Python requirements
289
- COPY requirements.txt ./
290
- RUN pip install --no-cache-dir -r requirements.txt
291
-
292
- COPY . .
293
-
294
- CMD ["uvicorn", "fastapi_example:app", "--host", "0.0.0.0", "--port", "8000"]
295
- ```
296
-
297
- ---
298
-
299
- ## Running the Verification Suite
300
-
301
- Run all tests, benchmarks, and concurrency assertions:
302
-
303
- ```bash
304
- # Automated Test Suite (10 tests, 0.3s)
305
- python3 test_python_bridge.py
306
-
307
- # Interactive Examples
308
- python3 fastapi_example.py
309
- python3 langchain_example.py
310
- python3 llamaindex_example.py
311
- ```
@@ -1,18 +0,0 @@
1
- MANIFEST.in
2
- README.md
3
- bridge_daemon.cjs
4
- pyproject.toml
5
- setup.py
6
- privacyscrubber/__init__.py
7
- privacyscrubber/bridge_daemon.cjs
8
- privacyscrubber/cli.py
9
- privacyscrubber/client.py
10
- privacyscrubber/exceptions.py
11
- privacyscrubber/langchain.py
12
- privacyscrubber/types.py
13
- privacyscrubber.egg-info/PKG-INFO
14
- privacyscrubber.egg-info/SOURCES.txt
15
- privacyscrubber.egg-info/dependency_links.txt
16
- privacyscrubber.egg-info/entry_points.txt
17
- privacyscrubber.egg-info/requires.txt
18
- privacyscrubber.egg-info/top_level.txt
@@ -1,3 +0,0 @@
1
- [console_scripts]
2
- privacyscrubber = privacyscrubber.cli:main
3
- ps-bridge = privacyscrubber.cli:main
@@ -1,18 +0,0 @@
1
-
2
- [all]
3
- fastapi>=0.100.0
4
- uvicorn>=0.20.0
5
- pydantic>=2.0.0
6
- langchain-core>=0.1.0
7
- llama-index-core>=0.10.0
8
-
9
- [fastapi]
10
- fastapi>=0.100.0
11
- uvicorn>=0.20.0
12
- pydantic>=2.0.0
13
-
14
- [langchain]
15
- langchain-core>=0.1.0
16
-
17
- [llamaindex]
18
- llama-index-core>=0.10.0
@@ -1 +0,0 @@
1
- privacyscrubber