Python SDK for Xybern Redact — anonymize PII before it reaches any LLM
Project description
xybern-redact
Python SDK for Xybern Redact — anonymize PII before it reaches any LLM and restore real values in the response.
pip install xybern-redact
Requirements
- Python 3.9+
- A Xybern workspace with an API key (
xr_live_...) — get one at xybern.com
Quick start
from xybern_redact import RedactClient
client = RedactClient(api_key="xr_live_YOUR_KEY")
result = client.anonymize("Michael Chen signed the contract on 12 March 2024.")
print(result.text)
# "Morgan Ross signed the contract on 11 April 2024."
print(result.entity_count) # 2
print(result.entities) # {"PERSON": 1, "DATE": 1}
Anonymize then call any LLM yourself
from xybern_redact import RedactClient
from anthropic import Anthropic
redact = RedactClient(api_key="xr_live_YOUR_KEY")
llm = Anthropic(api_key="sk-ant-...")
# Strip PII before sending
anon = redact.anonymize("Summarise the contract signed by Michael Chen at Goldman Sachs.")
# Call the LLM with the clean text
response = llm.messages.create(
model="claude-sonnet-4-6",
max_tokens=512,
messages=[{"role": "user", "content": anon.text}],
)
# Restore real names in the response
original = redact.deanonymize(response.content[0].text, anon.entity_map)
print(original)
# Michael Chen and Goldman Sachs are restored.
Use the built-in proxy
The proxy handles anonymization and de-anonymization automatically:
response = client.chat(
model="claude-sonnet-4-6",
messages=[{"role": "user", "content": "Summarise the contract signed by Michael Chen."}],
)
print(response.content)
# Response already has real names restored.
Anonymize a file
result = client.anonymize_file("contract.pdf")
with open("contract_clean.pdf", "wb") as f:
f.write(result.content)
print(f"{result.entity_count} entities anonymized")
Multi-turn conversations
thread = "session_abc123"
r1 = client.anonymize("Michael Chen signed.", thread_id=thread)
r2 = client.anonymize("Chen reviewed the annexes.", thread_id=thread)
# Both map "Chen" to the same pseudonym across the thread.
Error handling
from xybern_redact import RedactClient, AuthenticationError, APIError
try:
client = RedactClient(api_key="xr_live_YOUR_KEY")
result = client.anonymize(text)
except AuthenticationError:
print("Invalid or missing API key.")
except APIError as e:
print(f"Server error {e.status_code}: {e}")
Context manager
with RedactClient(api_key="xr_live_YOUR_KEY") as client:
result = client.anonymize("...")
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xybern_redact-0.1.2.tar.gz
(174.9 kB
view details)
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 xybern_redact-0.1.2.tar.gz.
File metadata
- Download URL: xybern_redact-0.1.2.tar.gz
- Upload date:
- Size: 174.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e20e74ce80eadb48805510097335c57b24e3c23325b059589812402b813ec4a2
|
|
| MD5 |
a97277e578b8b6ba7d554d576dfeda7b
|
|
| BLAKE2b-256 |
7b5aaabe376629085db5d560684b06c5f0385b41aeb9e238b33f7e7cc12840aa
|
File details
Details for the file xybern_redact-0.1.2-py3-none-any.whl.
File metadata
- Download URL: xybern_redact-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa8f9739b1eeaa7b3d1277e1c953e08c8456e459097e0072a3f53387e1f78baa
|
|
| MD5 |
0d9b2efa942e27a9c78c57ae3ffb2865
|
|
| BLAKE2b-256 |
7b0129c54cf6b412b812db815ff5acbcec21c44ebcecadb10ee44e3baa993296
|