Python SDK — Client
The Python SDK provides two client classes: PiiRedactor for synchronous usage and AsyncPiiRedactor for async/await usage. Both share the same interface and configuration options.
PiiRedactor (Sync)
from pii_redactor_sdk import PiiRedactor
client = PiiRedactor(
api_key: str,
base_url: str = "https://api.pii-redactor.dev",
timeout: float = 30.0,
max_retries: int = 3,
)Constructor Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | required | Your API key |
base_url | str | https://api.pii-redactor.dev | API base URL |
timeout | float | 30.0 | Request timeout in seconds |
max_retries | int | 3 | Max 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 accessConvenience 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 pii_redactor_sdk import PiiRedactor
client = PiiRedactor(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}")AsyncPiiRedactor
from pii_redactor_sdk import AsyncPiiRedactor
client = AsyncPiiRedactor(
api_key: str,
base_url: str = "https://api.pii-redactor.dev",
timeout: float = 30.0,
max_retries: int = 3,
)AsyncPiiRedactor has the same constructor parameters, resources, and convenience methods as PiiRedactor, but all methods return coroutines that must be awaited.
Example
import asyncio
from pii_redactor_sdk import AsyncPiiRedactor
async def main():
client = AsyncPiiRedactor(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 = PiiRedactor(api_key="pk_live_...", max_retries=5)