Skip to Content

Python SDK — Client

The Python SDK provides two client classes: Expunct for synchronous usage and AsyncExpunct for async/await usage. Both share the same interface and configuration options.

Expunct (Sync)

from expunct import Expunct client = Expunct( api_key: str, base_url: str = "https://api.expunct.ai", timeout: float = 30.0, max_retries: int = 3, )

Constructor Parameters

ParameterTypeDefaultDescription
api_keystrrequiredYour API key
base_urlstrhttps://api.expunct.aiAPI base URL
timeoutfloat30.0Request timeout in seconds
max_retriesint3Max retries with exponential backoff

Resources

The client exposes six resource objects:

client.redact # RedactResource -- text and URI redaction client.jobs # JobsResource -- job management client.batch # BatchResource -- batch operations client.policies # PoliciesResource -- redaction policies client.api_keys # ApiKeysResource -- API key management client.audit # AuditResource -- audit log access

Convenience Methods

These methods provide shorthand access to common operations:

def sanitize_text(self, text: str, **kwargs) -> RedactResponse: """Redact PII from a text string. Delegates to client.redact.text().""" ... def sanitize_file(self, input_uri: str, **kwargs) -> JobResponse: """Submit a file for redaction. Delegates to client.redact.uri().""" ... def sanitize_uri(self, input_uri: str, **kwargs) -> JobResponse: """Submit a URI for redaction. Delegates to client.redact.uri().""" ...

Example

from expunct import Expunct client = Expunct(api_key="pk_live_...") # Inline text redaction result = client.sanitize_text( "John Smith lives at 123 Main St", pii_types=["PERSON", "ADDRESS"], ) print(result.redacted_text) # File redaction (async job) job = client.sanitize_file("s3://my-bucket/report.pdf") print(f"Job {job.id} status: {job.status}")

AsyncExpunct

from expunct import AsyncExpunct client = AsyncExpunct( api_key: str, base_url: str = "https://api.expunct.ai", timeout: float = 30.0, max_retries: int = 3, )

AsyncExpunct has the same constructor parameters, resources, and convenience methods as Expunct, but all methods return coroutines that must be awaited.

Example

import asyncio from expunct import AsyncExpunct async def main(): client = AsyncExpunct(api_key="pk_live_...") # All resource methods are async result = await client.redact.text( text="Contact jane@example.com for details", ) print(result.redacted_text) # Convenience methods are also async job = await client.sanitize_file("s3://bucket/doc.pdf") print(f"Job {job.id} created") # List jobs jobs = await client.jobs.list() for j in jobs: print(f" {j.id}: {j.status}") asyncio.run(main())

Authentication

Both clients authenticate using an API key passed to the constructor. The key is sent as a Bearer token in the Authorization header on every request.

# The SDK sends this header automatically: # Authorization: Bearer pk_live_...

Retry Behavior

The SDK automatically retries requests on transient failures (HTTP 429, 500, 502, 503, 504) using exponential backoff with jitter. The max_retries parameter controls the maximum number of retry attempts.

# Retry up to 5 times with exponential backoff client = Expunct(api_key="pk_live_...", max_retries=5)