Skip to main content

Official Python SDK for AIGC Compliance API - AI content detection and watermarking

Project description

AIGC Compliance Python SDK

PyPI version Python 3.7+ License: MIT GitHub

Official Python SDK for AIGC Compliance API - AI content detection and watermarking with EU GDPR and China Cybersecurity Law compliance.

🌟 Professional SDK | ⚡ High Performance | 🛡️ Enterprise Ready | 🌍 Global Compliance

🚀 Quick Start

Installation

pip install aigc-compliance

Basic Usage

from aigc_compliance import ComplianceClient

# Initialize client
client = ComplianceClient(api_key="your_api_key_here")

# Process image for AI detection and compliance
result = client.comply(
    file_path="image.jpg", 
    region="EU",
    watermark_position="bottom-right",
    include_base64=True
)

print(f"Compliant: {result['compliant']}")
print(f"AI Probability: {result['ai_probability']}")
print(f"Processing Time: {result['processing_time']}ms")

🌍 Compliance Regions

EU GDPR Compliance

result = client.comply(
    file_path="image.jpg",
    region="EU",
    watermark_position="bottom-right"
)
# Returns compliance result with EU GDPR metadata

China Cybersecurity Law Compliance

result = client.comply(
    file_path="image.jpg", 
    region="CN",
    watermark_position="top-left",
    logo_file="custom_logo.png",
    save_to_disk=True
)
# Returns compliance result with China Cybersecurity Law compliance

📖 Features

✅ Core Features (All Plans)

  • AI Content Detection: Advanced ML models for AI-generated content identification
  • Watermarking: Automatic watermark application with custom text and logos
  • Multi-Region Compliance: EU GDPR and China Cybersecurity Law support
  • Rate Limiting: Built-in rate limit handling with exponential backoff
  • Error Handling: Comprehensive error types with detailed messages

🚀 Pro Features

  • Custom Watermarks: Personalized watermark text and positioning
  • Metadata Levels: Basic and detailed compliance metadata
  • Legacy Support: /v1/tag endpoint for URL-based processing

🏢 Enterprise Features

  • Batch Processing: Process up to 100 images in a single request
  • Webhooks: Real-time notifications for completed processing
  • Advanced Analytics: Detailed usage statistics and insights
  • Custom Metadata: Attach additional metadata to processing requests

📚 API Reference

ComplianceClient

Constructor

ComplianceClient(
    api_key: str,
    base_url: Optional[str] = None,
    timeout: float = 30,
    max_retries: int = 3,
    user_agent: Optional[str] = None
)

Core Methods

comply()

Process image for AI detection and compliance watermarking.

def comply(
    file_path: str,
    region: str = "EU",
    watermark_position: str = "bottom-right",
    logo_file: Optional[str] = None,
    include_base64: bool = True,
    save_to_disk: bool = False,
    output_path: Optional[str] = None
) -> ComplianceResponse

Parameters:

  • image: Image file (file object, bytes, or file path)
  • region: Compliance region ("eu" for GDPR, "cn" for China)
  • watermark_text: Custom watermark text
  • watermark_logo: Whether to apply logo watermark
  • metadata_level: Level of compliance metadata
  • custom_metadata: Additional metadata (Enterprise only)

Returns:

{
    "is_ai_generated": bool,
    "confidence": float,
    "watermark_applied": bool,
    "processing_time_ms": int,
    "quota_remaining": int,
    "compliance_metadata": {
        "ai_generated_probability": float,
        "content_type": str,
        "processing_timestamp": str,
        "gdpr_compliant": bool,  # EU region
        # For China region (detailed):
        "cybersecurity_law_compliance": bool,
        "watermark_info": {...},
        "content_labeling": {...}
    }
}
tag() (Legacy)

Process image from URL (Pro/Enterprise only).

def tag(
    image_url: str,
    region: Literal["eu", "cn"] = "eu",
    watermark_text: Optional[str] = None,
    watermark_logo: bool = True,
    metadata_level: Literal["basic", "detailed"] = "basic",
) -> ComplianceResponse
batch_process() (Enterprise)

Process multiple images in batch.

def batch_process(
    items: List[BatchItem],
    region: Literal["eu", "cn"] = "eu",
    watermark_logo: bool = True,
    metadata_level: Literal["basic", "detailed"] = "basic",
) -> BatchResponse

Example:

items = [
    {"id": "img1", "image": image1_bytes, "custom_metadata": {"source": "upload"}},
    {"id": "img2", "image": image2_bytes, "custom_metadata": {"source": "api"}},
]
result = client.batch_process(items, region="eu")
get_analytics() (Enterprise)

Get usage analytics and insights.

def get_analytics(
    period: Optional[str] = None,
    start_date: Optional[str] = None,
    end_date: Optional[str] = None,
) -> AnalyticsResponse
Webhook Management (Enterprise)
# Register webhook
webhook = client.register_webhook(
    url="https://your-app.com/webhooks/compliance",
    events=["compliance.completed", "batch.finished"],
    secret="your_webhook_secret"
)

# List webhooks
webhooks = client.list_webhooks()

# Delete webhook
client.delete_webhook(webhook_id="webhook_123")

🔧 Advanced Usage

Context Manager

with ComplianceClient(api_key="your_key") as client:
    result = client.comply(image, region="eu")
    # Client automatically closed

Error Handling

from aigc_compliance import (
    ComplianceClient,
    ComplianceAuthenticationError,
    ComplianceQuotaExceededError,
    ComplianceRateLimitError,
)

try:
    result = client.comply(image)
except ComplianceAuthenticationError:
    print("Invalid API key")
except ComplianceQuotaExceededError as e:
    print(f"Quota exceeded: {e.quota_used}/{e.quota_limit}")
except ComplianceRateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")

Custom Configuration

client = ComplianceClient(
    api_key="your_key",
    base_url="https://custom-api.example.com",
    timeout=60,
    max_retries=5,
    user_agent="MyApp/1.0"
)

📊 Response Examples

Basic EU Response

{
  "is_ai_generated": true,
  "confidence": 0.95,
  "watermark_applied": true,
  "processing_time_ms": 1250,
  "quota_remaining": 245,
  "compliance_metadata": {
    "ai_generated_probability": 0.95,
    "content_type": "image/jpeg",
    "processing_timestamp": "2024-01-15T10:30:45Z",
    "gdpr_compliant": true
  }
}

Detailed China Response

{
  "is_ai_generated": true,
  "confidence": 0.97,
  "watermark_applied": true,
  "processing_time_ms": 1450,
  "quota_remaining": 244,
  "compliance_metadata": {
    "ai_generated_probability": 0.97,
    "content_type": "image/jpeg",
    "processing_timestamp": "2024-01-15T10:30:45Z",
    "cybersecurity_law_compliance": true,
    "watermark_info": {
      "text": "AI生成内容",
      "logo_applied": true,
      "position": "bottom-right",
      "transparency": 0.7
    },
    "content_labeling": {
      "category": "ai_generated",
      "compliance_level": "full",
      "regulatory_notes": "符合网络安全法要求"
    }
  }
}

🔐 Authentication

  1. Get API Key: Sign up at AIGC Compliance Dashboard
  2. Set API Key:
    # Method 1: Direct initialization
    client = ComplianceClient(api_key="sk_live_...")
    
    # Method 2: Environment variable
    import os
    client = ComplianceClient(api_key=os.getenv("AIGC_API_KEY"))
    

📈 Plans & Quotas

Plan Monthly Quota Features
Free 10 requests Basic detection, EU watermarks
Starter 100 requests Custom watermarks, both regions
Pro 1,000 requests Legacy endpoints, detailed metadata
Enterprise 10,000+ requests Batch processing, webhooks, analytics

🛠️ Development

Requirements

  • Python 3.7+
  • requests >= 2.25.0

Optional Dependencies

# Development tools
pip install aigc-compliance[dev]

Testing

import pytest
from aigc_compliance import ComplianceClient

def test_compliance_detection():
    client = ComplianceClient(api_key="test_key")
    # Add your test image
    with open("test_image.jpg", "rb") as f:
        result = client.comply(f)
    assert "is_ai_generated" in result

🔗 Links

📄 License

MIT License - see LICENSE file for details.


Need help? Check our comprehensive documentation or contact support@aigc-compliance.com.

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

aigc_compliance-1.0.2.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

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

aigc_compliance-1.0.2-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file aigc_compliance-1.0.2.tar.gz.

File metadata

  • Download URL: aigc_compliance-1.0.2.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for aigc_compliance-1.0.2.tar.gz
Algorithm Hash digest
SHA256 3a5c1fc60eba5ef094840a7c065f0f82f2c4d5f8c5530058ef18a3af0d5aed90
MD5 0b9a16d71c63cba97b4d43496b4e63fb
BLAKE2b-256 07c70047700a4c2112c44b22bb84fde9f53585f980c90827c0136a5ec4c60398

See more details on using hashes here.

File details

Details for the file aigc_compliance-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aigc_compliance-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 21f3b4d0956effcb5a3fd6759d043749243d3ba01e7804559c6992e39f773566
MD5 8cc0de480dc41e8f37264dff5fd76d56
BLAKE2b-256 5d9c67f59901329d77e32131c6aec48ff1a49456913c895a4ae8c14bdf82b1a9

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