Skip to main content

Python SDK for Xybern Redact — anonymize PII before it reaches any LLM

Project description

Xybern Redact

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.3.tar.gz (174.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xybern_redact-0.1.3-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file xybern_redact-0.1.3.tar.gz.

File metadata

  • Download URL: xybern_redact-0.1.3.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

Hashes for xybern_redact-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f844be061c0ba16232883fe5a3c528416f84d858d2bfcb0f5a92ae356846fd62
MD5 a8aad0d7f7578154cfd57327111d79ff
BLAKE2b-256 f7d76d21aea2689705ea64c178886f3428836fb4ebd1bfbed8cbbd39a839dce3

See more details on using hashes here.

File details

Details for the file xybern_redact-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: xybern_redact-0.1.3-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

Hashes for xybern_redact-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e65018dfa4f4f9a0edaa22029ab19d39bce62d24b248d80074db3005546cc809
MD5 3a10be29d18d18ef03f690b31ac3c1ff
BLAKE2b-256 ae3f6cccc05434900bfe001d19cb540bfeb327c1eebd53359842242da6bed530

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page