Skip to main content

Python SDK for the PrivaBase privacy and compliance API

Project description

PrivaBase Python SDK

A comprehensive Python SDK for the PrivaBase privacy and compliance API. Build, manage, and maintain compliance across multiple frameworks (GDPR, CCPA, and more) with ease.

Python Version License

Features

  • 🔐 Type-safe: Full type hints throughout (Python 3.8+)
  • Automatic Retries: Exponential backoff with rate limit handling
  • 📊 Comprehensive: Covers compliance, documents, frameworks, DSR, monitoring, vendors, and trust center
  • 🔄 Context Manager: Proper resource management with with statement
  • 📝 Well Documented: Detailed docstrings and examples
  • 🧪 Fully Tested: Comprehensive test suite with mocked HTTP

Installation

pip install privabase

Optional Dependencies

For async support:

pip install privabase[async]

For development:

pip install privabase[dev]

Quick Start

from privabase import PrivaBase

# Initialize the client
client = PrivaBase(api_key="pk_your_api_key")

# Check compliance
result = client.compliance.check(
    framework="gdpr",
    data_practices={
        "collects_personal_data": True,
        "has_privacy_policy": True,
        "data_retention_defined": False
    }
)

print(f"Compliant: {result.compliant}")
print(f"Score: {result.score}")
print(f"Recommendations: {result.recommendations}")

API Reference

Client Initialization

client = PrivaBase(
    api_key="pk_xxx",  # Required
    base_url="https://privacy-compliance-api.vercel.app",  # Optional
    timeout=30,  # Optional, seconds
    max_retries=3  # Optional, automatic retries
)

Compliance Module

Check Compliance

result = client.compliance.check(
    framework="gdpr",
    data_practices={
        "collects_personal_data": True,
        "has_privacy_policy": True,
        "data_retention_defined": False
    }
)

# Returns ComplianceResult
print(result.compliant)  # bool
print(result.score)  # float (0-1)
print(result.issues)  # List of issues
print(result.recommendations)  # List of recommendations

Scan Privacy Policy

scan = client.compliance.scan_policy("https://example.com/privacy")

print(scan.found)  # bool
print(scan.content)  # str or None
print(scan.issues)  # List of issues found
print(scan.score)  # float

Get Compliance Report

report = client.compliance.get_report("gdpr")
print(report)

Documents Module

Generate Document

doc = client.documents.generate(
    template="gdpr-privacy-policy",
    data={
        "company_name": "Acme Inc",
        "website": "https://acme.com",
        "contact_email": "privacy@acme.com"
    },
    format="pdf"  # or "docx", "markdown"
)

print(doc.id)  # Document ID
print(doc.url)  # Download URL
print(doc.content)  # Document content

List Templates

templates = client.documents.list_templates()
for template in templates:
    print(f"{template['id']}: {template['name']}")

Get Template Details

template = client.documents.get_template("gdpr-privacy-policy")
print(template['required_fields'])
print(template['description'])

Regenerate Document

doc = client.documents.regenerate(
    document_id="doc_123",
    data={"company_name": "New Name"}
)

Delete Document

success = client.documents.delete("doc_123")

Frameworks Module

List All Frameworks

frameworks = client.frameworks.list()
for fw in frameworks:
    print(f"{fw.name} (v{fw.version})")
    print(f"  Regions: {', '.join(fw.regions)}")
    print(f"  Categories: {', '.join(fw.categories)}")

Get Framework Details

framework = client.frameworks.get("gdpr")
print(framework.description)
print(framework.regions)  # List of applicable regions

List by Region

eu_frameworks = client.frameworks.list_by_region("EU")

Search Frameworks

results = client.frameworks.search("data protection")

DSR (Data Subject Request) Module

Create DSR

dsr = client.dsr.create(
    type="access",  # or "deletion", "portability", "rectification"
    email="user@example.com",
    framework="gdpr",
    metadata={"reason": "user initiated"}
)

print(dsr.id)
print(dsr.status)  # "pending", "in_progress", "completed", "denied"

Get DSR

dsr = client.dsr.get("dsr_123")
print(dsr.status)
print(dsr.updated_at)

List DSRs

pending_requests = client.dsr.list(
    framework="gdpr",
    status="pending"
)

Update DSR Status

dsr = client.dsr.update_status("dsr_123", "completed")

Delete DSR

success = client.dsr.delete("dsr_123")

Monitoring Module

Create Monitoring Schedule

schedule = client.monitoring.create_schedule(
    framework="gdpr",
    frequency="weekly",  # or "daily", "monthly"
    enabled=True
)

print(schedule.id)
print(schedule.next_check)

Get Schedule

schedule = client.monitoring.get_schedule("sched_123")

List Schedules

schedules = client.monitoring.list_schedules(
    framework="gdpr",
    enabled=True
)

Update Schedule

schedule = client.monitoring.update_schedule(
    "sched_123",
    frequency="daily",
    enabled=False
)

Delete Schedule

success = client.monitoring.delete_schedule("sched_123")

Run Manual Check

result = client.monitoring.run_check("sched_123")

Vendors Module

Assess Vendor

risk = client.vendors.assess_vendor(
    vendor_name="Cloud Storage Provider",
    categories=["data_security", "compliance"]
)

print(risk.risk_level)  # "low", "medium", "high", "critical"
print(risk.score)  # 0-1
print(risk.recommendations)

Get Vendor Assessment

risk = client.vendors.get_vendor("vendor_123")

List Vendors

risky_vendors = client.vendors.list_vendors(risk_level="high")

Reassess Vendor

risk = client.vendors.reassess_vendor("vendor_123")

Delete Vendor

success = client.vendors.delete_vendor("vendor_123")

Trust Center Module

Get Trust Center Info

info = client.trust_center.get_info()

print(info.certifications)  # List of certifications
print(info.compliance_frameworks)  # Supported frameworks
print(info.security_practices)  # List of practices
print(info.data_centers)  # Data center information

Get Certifications

certs = client.trust_center.get_certifications()

Get Compliance Status

status = client.trust_center.get_compliance_status()

Get Security Practices

practices = client.trust_center.get_security_practices()

Get Data Center Info

dc_info = client.trust_center.get_data_center_info()

Error Handling

The SDK provides specific exception classes for different error scenarios:

from privabase import (
    PrivaBaseError,
    AuthenticationError,
    RateLimitError,
    ValidationError,
    NotFoundError,
    ServerError,
)

try:
    result = client.compliance.check(...)
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except ValidationError as e:
    print(f"Invalid request: {e.message}")
except NotFoundError:
    print("Resource not found")
except ServerError:
    print("Server error, please try again")
except PrivaBaseError as e:
    print(f"API error: {e.message}")

Context Manager

Use the client as a context manager for proper resource cleanup:

with PrivaBase(api_key="pk_xxx") as client:
    result = client.compliance.check(...)
    # Resources are automatically cleaned up

Automatic Retries

The SDK automatically retries failed requests with exponential backoff:

  • Rate limit errors (429): Always retried
  • Other errors: Retried up to max_retries times
  • Exponential backoff: Delay = 1s × 2^(attempt-1), up to Retry-After header
client = PrivaBase(
    api_key="pk_xxx",
    max_retries=3  # Default
)

Type Hints

All responses include proper type hints:

from privabase import (
    ComplianceResult,
    Framework,
    Document,
    DSRRequest,
    MonitoringSchedule,
    VendorRisk,
    TrustCenterInfo,
    PolicyScan,
)

# IDE autocomplete and type checking work seamlessly
result: ComplianceResult = client.compliance.check(...)
frameworks: List[Framework] = client.frameworks.list()

Testing

Run the test suite:

pytest tests/

With coverage:

pytest tests/ --cov=privabase --cov-report=html

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Changelog

1.0.0 (2024-02-10)

  • Initial release
  • Compliance checking
  • Document generation
  • Framework listing
  • DSR management
  • Monitoring schedules
  • Vendor risk assessment
  • Trust center information

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

privabase-1.0.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

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

privabase-1.0.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file privabase-1.0.0.tar.gz.

File metadata

  • Download URL: privabase-1.0.0.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for privabase-1.0.0.tar.gz
Algorithm Hash digest
SHA256 28cc8cfc9e581546acb241b7e5224bb451cce8e3f26c44a3929e82b3b6241e0c
MD5 f00a3fb6c217dc74285d15dd7bf13ca8
BLAKE2b-256 dd843a04cc074f94fe9812bf8ff7625fa4c4297707899f72f9ced41a121b0512

See more details on using hashes here.

File details

Details for the file privabase-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: privabase-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for privabase-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 66cd8f68ceb2e24559fb845c21aeb266082e9cdc5be146116e56a633898e752d
MD5 f46c88aec6ec74bf1e18529fc3a92b47
BLAKE2b-256 69dfaff08e3ed54c1b3dfe191f60eb066846882f21fe80de44ba63f6fa656f77

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