PrivacyPal SDK
Official Python SDK for the PrivacyPal Data Twins API.
Overview
PrivacyPal SDK provides a simple interface for encoding sensitive data into synthetic "privacy twins" and decoding them back to original values with proper authorization. This enables safe handling of PII (Personally Identifiable Information) in your agents and applications.
Features
- Secure PII Handling - Automatically detects and replaces sensitive data with synthetic twins
- Bidirectional Flow - Encode sensitive data and decode it back when authorized
- Batch Processing - Process multiple records efficiently
- File Upload Support - Encode PII in PDFs, DOCX, CSV, images, and more
- Easy Integration - Simple, intuitive Pythonic API
Installation
pip install privacypal-sdk
Quick Start
Natural Language Prompts
PrivacyPal works seamlessly with natural language prompts and instructions:
from privacypal_sdk import PrivacyPalClient
# Initialize the client
client = PrivacyPalClient(
api_url="https://api.privacypal.ai",
api_key="your-jwt-token",
)
# Your natural language prompt with embedded PII
prompt = (
"I want to analyze the average credit debt that John Doe would experience "
"being that his credit is poor even though his income is high. When completed "
"draft an email to john@email.com so we can send this report to him."
)
# Encode: Automatically detects and protects PII
result = client.encode(
data=prompt,
source_container="ai_prompts.credit_analysis",
)
print("Protected:", result["encodedData"])
# "...analyze the average credit debt that Jane Smith would experience..."
# "...draft an email to jane.smith@example.com..."
print("Continuation ID:", result["continuationId"])
print("PII Protected:", len(result["transformations"]), "entities")
# Decode back to original (with authorization)
decoded = client.decode(
continuation_id=result["continuationId"],
data=result["encodedData"],
sensitive_hashes=[t["originalHash"] for t in result["transformations"]],
authorization={
"token": "your-jwt-token",
"purpose": "Credit analysis report generation",
},
)
print("Original:", decoded["decodedData"])
# Exact original prompt perfectly restored
Simple PII List
You can also encode simple lists of sensitive data:
result = client.encode(
data="John Doe, SSN: 123-45-6789, email: john@company.com",
source_container="customer_db.users",
metadata={"rowId": "1001"},
)
API Reference
Client Initialization
client = PrivacyPalClient(
api_url="https://api.privacypal.ai", # PrivacyPal API base URL
api_key="your-jwt-token", # JWT access token
timeout=30, # Request timeout in seconds (default: 30)
)
Encoding
client.encode(...)
Encode a single data item containing sensitive information.
Parameters:
data— Input text containing potential PIIsource_container— Source identifier (e.g."customer_db.users")source_element— Element identifier (e.g."personal_info")metadata— Additional metadata dict (rowId,sourceTable, etc.)score_threshold— PII detection threshold (default:0.35)language— Language code (default:"en")continuation_id— Optional ID for correlation
Returns a dict:
encodedData— Data with PII replaced by synthetic twinscontinuationId— ID for later decodingtransformations— List of transformations appliedstatistics— Processing statistics
Example:
result = client.encode(
data="Patient: Alice Johnson, DOB: 03/15/1985, SSN: 987-65-4321",
source_container="medical_db.patients",
metadata={"rowId": "P12345", "recordType": "patient_intake"},
)
client.encode_batch(items)
Encode multiple data items in a single request. All items share the same continuationId.
Example:
result = client.encode_batch([
{
"data": "Employee: Bob Williams, SSN: 111-22-3333",
"source_container": "hr_db.employees",
"metadata": {"rowId": "E001"},
},
{
"data": "Employee: Carol Davis, SSN: 444-55-6666",
"source_container": "hr_db.employees",
"metadata": {"rowId": "E002"},
},
])
client.encode_file(file_content, file_name, ...)
Encode a file by uploading it for server-side PII detection. Supports PDF, DOCX, CSV, images, and more.
Example:
with open("report.pdf", "rb") as f:
result = client.encode_file(f.read(), "report.pdf")
Decoding
client.decode(...)
Decode synthetic twins back to original sensitive data (requires authorization).
Parameters:
continuation_id— ID from the encoding responsedata— Data containing synthetic twinssensitive_hashes— List of original value hashes to decodeauthorization— Dict withtokenandpurposekeys
Returns a dict:
decodedData— Data with twins replaced by originalstransformations— List of decoded transformationsauditLog— Audit informationstatistics— Processing statistics
Example:
result = client.decode(
continuation_id="abc-123-def",
data=encode_result["encodedData"],
sensitive_hashes=[t["originalHash"] for t in encode_result["transformations"]],
authorization={
"token": "jwt-token",
"purpose": "Medical records review for patient care",
},
)
Dataset Management
client.get_dataset_twins(continuation_id)
Retrieve all data twins for a specific dataset.
Example:
result = client.get_dataset_twins("abc-123-def")
print(f"Found {result['count']} twins")
for twin in result["twins"]:
print(twin["entityType"], twin["catalogItemId"])
Configuration Methods
client.update_api_key(new_api_key)
Update the API key for authentication.
client.update_api_url(new_api_url)
Update the API base URL.
client.get_config()
Get the current configuration as a dict.
Entity Types
The SDK detects and handles various PII entity types:
PERSON— Person namesEMAIL_ADDRESS— Email addressesPHONE_NUMBER— Phone numbersUS_SSN— US Social Security NumbersCREDIT_CARD— Credit card numbersLOCATION— Addresses and locationsDATE_TIME— Dates and timestampsIP_ADDRESS— IP addresses- And more...
Error Handling
The SDK provides a structured exception hierarchy:
from privacypal_sdk import (
PrivacyPalError,
AuthenticationError,
TrialExpiredError,
NetworkError,
RequestError,
)
try:
result = client.encode(data="...")
except AuthenticationError:
print("Invalid or expired token")
except TrialExpiredError:
print("Subscription required")
except NetworkError:
print("Cannot reach the API")
except PrivacyPalError as e:
print(f"API error: {e}")
Best Practices
- Store Continuation IDs — Always save the
continuationIdfor later decoding - Store Hashes — Keep track of
originalHashvalues from transformations for selective decoding - Authorization Purpose — Provide clear, specific purposes for audit trails
- Batch Processing — Use
encode_batchfor multiple records to improve performance - Error Handling — Always wrap API calls in try/except blocks
Performance
Typical latencies:
- Encoding: 70–280ms per record
- Decoding: 20–65ms per record
- Batch Encoding: 50–200ms average per record
- Get Dataset Twins: 10–30ms
License
MIT
Support
For issues and questions:
- GitHub: PrivacyPal/privacypal-cloud
- Documentation: docs.privacypal.com
Metadata
Release files for privacypal-sdk 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| privacypal_sdk-1.0.1.tar.gz | 13.5 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| privacypal_sdk-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / privacypal_sdk-1.0.1.tar.gz
| Download URL | privacypal_sdk-1.0.1.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0aef7111cfd2803085c61bc60c2a970576d0cdc0d5e1ecc48fbe046007391e50
|
|
BLAKE2b-256 checksum How to use checksums |
55dcdc154357d80dfc298bbcd5e2ed55c66bf3780a9aec1888002d346e1db2ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 26, 2026.
Transparency logRelease files / privacypal_sdk-1.0.1-py3-none-any.whl
| Download URL | privacypal_sdk-1.0.1-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
557928d1c1a4edeeaf22a330236b3c195d073549b5f1dec3ad88fbfd95b395ad
|
|
BLAKE2b-256 checksum How to use checksums |
dd346441298d3619d668209fd6538d6db129ef20ae83d7d186db22199d1cb08a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 26, 2026.
Transparency logSecurity for privacypal-sdk 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for privacypal_sdk-1.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.