Skip to main content

Privacy Infrastructure for Enterprise AI — Official Python SDK

Project description

Privaro Python SDK

Privacy Infrastructure for Enterprise AI — Official Python SDK by iCommunity Labs

Protect PII in AI prompts with one line of code. Every interaction is tokenized, audited, and blockchain-certified.


Installation

pip install privaro

No required dependencies — uses Python stdlib only.

# Optional: async support
pip install privaro[async]

Quick Start

import privaro

# Initialize once (e.g., at app startup)
privaro.init(
    api_key="prvr_your_api_key",
    pipeline_id="your-pipeline-uuid",
)

# Protect a prompt before sending to any LLM
result = privaro.protect("Patient: María García, DNI 34521789X, IBAN ES91 2100...")

print(result.protected)      # "Patient: [NM-0001], DNI [ID-0001], IBAN [BK-0001]..."
print(result.risk_score)     # 0.847
print(result.risk_level)     # "high"
print(result.gdpr_compliant) # True

# Send protected prompt to your LLM — no PII ever reaches the model
response = openai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": result.protected}]
)

Usage Patterns

Protect + LLM (full pipeline)

import privaro
import openai

privaro.init(api_key="prvr_xxx", pipeline_id="uuid")

def ask_ai(user_input: str) -> str:
    # 1. Protect PII
    protected = privaro.protect(user_input)

    if not protected.is_safe:
        raise ValueError(f"PII leak detected: {protected.leaked} entities exposed")

    # 2. Call LLM with protected prompt
    response = openai.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": protected.protected}]
    )

    return response.choices[0].message.content

Detect only (analysis mode)

result = privaro.detect("Call me at 612 345 678, email: user@company.es")

for detection in result.detections:
    print(f"{detection.type}: {detection.severity} ({detection.detector})")
# phone: high (regex)
# email: high (regex)

Agent mode (stricter policies)

result = privaro.protect(
    prompt=agent_input,
    agent_mode=True,   # Applies stricter policy preset
)

Multiple clients (multiple pipelines)

from privaro import PrivaroClient

legal_client = PrivaroClient(api_key="prvr_xxx", pipeline_id="legal-pipeline-uuid")
hr_client = PrivaroClient(api_key="prvr_xxx", pipeline_id="hr-pipeline-uuid")

legal_result = legal_client.protect(contract_text)
hr_result = hr_client.protect(employee_record)

Async support

from privaro.async_client import AsyncPrivaroClient

client = AsyncPrivaroClient(api_key="prvr_xxx", pipeline_id="uuid")

async def process(prompt: str):
    result = await client.protect(prompt)
    return result.protected

Error handling

from privaro.exceptions import AuthError, PolicyBlockError, ProxyUnavailableError

try:
    result = privaro.protect(prompt)
except PolicyBlockError as e:
    # Request blocked by policy (e.g., health data on non-approved provider)
    logger.warning(f"Request blocked: {e}")
    return "Request cannot be processed — sensitive data detected."
except ProxyUnavailableError:
    # Fallback: log and fail safely
    logger.error("Privaro proxy unavailable")
    raise
except AuthError:
    logger.error("Invalid Privaro API key")
    raise

ProtectResult Reference

Property Type Description
result.protected str Prompt with PII replaced by tokens
result.original str Original prompt (local only)
result.risk_score float 0.0–1.0 composite risk score
result.risk_level str "high" / "medium" / "low"
result.gdpr_compliant bool True if no PII leaked
result.is_safe bool True if all PII masked
result.has_pii bool True if any entities detected
result.total_detected int Total PII entities found
result.total_masked int Entities successfully masked
result.leaked int Entities that passed through
result.detections list[Detection] Per-entity details
result.audit_log_id str Supabase audit log UUID
result.processing_ms int Proxy latency in ms
result.summary() str One-line log summary

Detection Reference

Property Values
detection.type dni iban email full_name phone health_record credit_card ip_address date_of_birth
detection.severity critical high medium low
detection.action tokenised anonymised blocked
detection.detector regex presidio
detection.confidence 0.0–1.0
detection.is_high_risk bool

Blockchain Verification

Every protect() call creates an immutable audit entry certified on Fantom Opera Mainnet via iBS. Verify any event at:

https://checker.icommunitylabs.com/check/fantom_opera_mainnet/{tx_hash}

Access the TX hash from your Privaro dashboard → Audit Logs → ⛓️ badge.


Requirements

  • Python 3.9+
  • Zero required dependencies (uses urllib from stdlib)
  • Optional: aiohttp>=3.9 for async support

License

MIT — © 2026 iCommunity Labs · privaro.io

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

privaro-0.2.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

privaro-0.2.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file privaro-0.2.0.tar.gz.

File metadata

  • Download URL: privaro-0.2.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for privaro-0.2.0.tar.gz
Algorithm Hash digest
SHA256 838c8d0ad6c6a30e5d5da14ab37f5e45352e105883c5589cf05ce0af55916a87
MD5 dcd0d3160ef410433da45f0cc306c98a
BLAKE2b-256 3c0bb3ac4f3e5cb0193d4ec5e77c59a1874a9075ff79bcc038233c9779252913

See more details on using hashes here.

File details

Details for the file privaro-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: privaro-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for privaro-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d60c8a00005629598f82f16a7785969ba26613550ce0d349fae3a5b8bac4d697
MD5 e380eb8e2190893ed05805289355147c
BLAKE2b-256 448f9bf8f1e42180de0a8bb6ba72b75e1d9e1e6bedff7cd2d133160fc7afd520

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page