Skip to main content

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.0.tar.gz (6.2 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.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xybern_redact-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 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.0.tar.gz
Algorithm Hash digest
SHA256 6516803416d5fad28a4e2bcfc43d2f9664c0c9dbcc9d61461f60fe1d4a91b11c
MD5 2007495a9333ffd81fb9ed6bba647e7c
BLAKE2b-256 316d6182049e39cb5e75c718f4fe41154c219e491b4c1631fcebef82a07e19dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xybern_redact-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a585282c43239e4d6300945028493e1f6529da5360896fb8f397f49b1e0fc044
MD5 74a26c7bb4b0e76d443db1b891d582d0
BLAKE2b-256 f433d6faf456448f191ba2b801d02a2fb7bb0be29e57c44d6e44d4ffc7ec3ee4

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