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
Metadata
Release files for xybern-redact 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| xybern_redact-0.1.3.tar.gz | 174.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xybern_redact-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 181.8 kB
Release files / xybern_redact-0.1.3.tar.gz
| Download URL | xybern_redact-0.1.3.tar.gz |
|---|---|
| Size | 174.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f844be061c0ba16232883fe5a3c528416f84d858d2bfcb0f5a92ae356846fd62
|
|
BLAKE2b-256 checksum How to use checksums |
f7d76d21aea2689705ea64c178886f3428836fb4ebd1bfbed8cbbd39a839dce3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Release files / xybern_redact-0.1.3-py3-none-any.whl
| Download URL | xybern_redact-0.1.3-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e65018dfa4f4f9a0edaa22029ab19d39bce62d24b248d80074db3005546cc809
|
|
BLAKE2b-256 checksum How to use checksums |
ae3f6cccc05434900bfe001d19cb540bfeb327c1eebd53359842242da6bed530
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|