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.1.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.1.tar.gz.
File metadata
- Download URL: xybern_redact-0.1.1.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 |
9d960e39d9886c738623bdc9a7cf616c2c6640afe04a45bd8647e31e0dd248cd
|
|
| MD5 |
2756b2bd8f8c0c0fb1d04d39d96b7020
|
|
| BLAKE2b-256 |
f6b3bfbfac6f665f80ee25d3533ca98abb78c69d05def26ee860590efe0d0537
|
File details
Details for the file xybern_redact-0.1.1-py3-none-any.whl.
File metadata
- Download URL: xybern_redact-0.1.1-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 |
8fc1434f813801efc03eaac6ddc362ce9bd445122974645601f4af2c0eeb919a
|
|
| MD5 |
ef6c809a5bb0b844c7310611f16cf147
|
|
| BLAKE2b-256 |
5c5ba488adc955349ee315d0a78b899e54b539ea1fac2ba71ae72a8ec15838c1
|