Python SDK — Getting Started
The Expunct Python SDK provides a type-safe client for the Expunct API, with both synchronous and asynchronous interfaces.
Requirements
- Python 3.10 or later
- Dependencies:
httpx,pydantic
Installation
pip install pii-redactor-sdkQuick Example
Synchronous
from pii_redactor_sdk import PiiRedactor
client = PiiRedactor(api_key="pk_live_...")
result = client.redact.text(
text="John Smith's email is john@example.com",
)
print(result.redacted_text)
# "[PERSON]'s email is [EMAIL_ADDRESS]"Asynchronous
import asyncio
from pii_redactor_sdk import AsyncPiiRedactor
async def main():
client = AsyncPiiRedactor(api_key="pk_live_...")
result = await client.redact.text(
text="John Smith's email is john@example.com",
)
print(result.redacted_text)
asyncio.run(main())Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | required | Your API key (starts with pk_live_ or pk_test_) |
base_url | str | https://api.pii-redactor.dev | API base URL |
timeout | float | 30.0 | Request timeout in seconds |
max_retries | int | 3 | Maximum retry attempts for transient failures |
client = PiiRedactor(
api_key="pk_live_...",
base_url="https://api.pii-redactor.dev",
timeout=60.0,
max_retries=5,
)Convenience Methods
The SDK provides shorthand methods for the most common operations:
# Redact text inline
result = client.sanitize_text("Call me at 555-0123")
# Redact a file (returns a job)
job = client.sanitize_file("s3://my-bucket/document.pdf")
# Redact content at a URI (returns a job)
job = client.sanitize_uri("https://example.com/page")Next Steps
- Client reference — full client API
- Resources — detailed resource documentation
- Models — Pydantic model reference
- Errors — error handling guide