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 expunctQuick Example
Synchronous
from expunct import Expunct
client = Expunct(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 expunct import AsyncExpunct
async def main():
client = AsyncExpunct(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.expunct.ai | API base URL |
timeout | float | 30.0 | Request timeout in seconds |
max_retries | int | 3 | Maximum retry attempts for transient failures |
client = Expunct(
api_key="pk_live_...",
base_url="https://api.expunct.ai",
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