Skip to main content

Python SDK for Vettly content moderation API

Project description

vettly

Content moderation that just works. One API for text, images, and video.

Installation

pip install vettly

Quick Start

from vettly import ModerationClient

client = ModerationClient("sk_live_...")

result = client.check(
    content="User-generated text",
    policy_id="community-safe"
)

if result.action == "block":
    # Content blocked
    pass

Get Your API Key

  1. Sign up at vettly.dev
  2. Go to Dashboard → API Keys
  3. Create and copy your key

Features

  • Text, images, video - One unified API for all content types
  • Custom policies - Define thresholds in YAML
  • Webhooks - Get notified when content is flagged
  • Dashboard - Monitor decisions and export logs
  • Automatic retries - Exponential backoff for rate limits and server errors
  • Async support - Full async/await support with AsyncModerationClient

Text Moderation

result = client.check(
    content="User-generated text",
    policy_id="community-safe"
)

print(result.action)      # 'allow' | 'flag' | 'block'
print(result.categories)  # List of CategoryResult
print(result.id)          # Decision ID for audit trail

Image Moderation

# From URL
result = client.check_image(
    image_url="https://example.com/image.jpg",
    policy_id="strict"
)

# From base64
result = client.check_image(
    image_url="data:image/jpeg;base64,/9j/4AAQ...",
    policy_id="strict"
)

Idempotency

Prevent duplicate processing with request IDs:

result = client.check(
    content="Hello",
    policy_id="default",
    request_id="unique-request-id-123"
)

Error Handling

The SDK provides typed exceptions for better error handling:

from vettly import (
    VettlyAuthError,
    VettlyRateLimitError,
    VettlyQuotaError,
    VettlyValidationError,
)

try:
    result = client.check(content="test", policy_id="default")
except VettlyAuthError:
    print("Invalid API key")
except VettlyRateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except VettlyQuotaError as e:
    print(f"Quota exceeded: {e.quota}")

Webhook Signature Verification

Verify webhook signatures to ensure authenticity:

from vettly import verify_webhook_signature, construct_webhook_event

@app.route("/webhooks/vettly", methods=["POST"])
def handle_webhook():
    payload = request.get_data(as_text=True)
    signature = request.headers.get("X-Vettly-Signature")

    if not verify_webhook_signature(payload, signature, webhook_secret):
        return "Invalid signature", 401

    event = construct_webhook_event(payload)

    if event["type"] == "decision.blocked":
        # Handle blocked content
        pass

    return "OK", 200

Async Support

from vettly import AsyncModerationClient

async with AsyncModerationClient("sk_live_...") as client:
    result = await client.check(
        content="User content",
        policy_id="community-safe"
    )

Configuration

from vettly import ModerationClient

client = ModerationClient(
    api_key="sk_live_...",
    api_url="https://api.vettly.dev",  # Optional: custom API URL
    timeout=30.0,                       # Optional: request timeout in seconds
    max_retries=3,                      # Optional: max retries for failures
    retry_delay=1.0,                    # Optional: base delay for backoff in seconds
)

FastAPI Example

from fastapi import FastAPI, HTTPException
from vettly import AsyncModerationClient

app = FastAPI()
client = AsyncModerationClient("sk_live_...")

@app.post("/comments")
async def create_comment(content: str):
    result = await client.check(content=content, policy_id="community-safe")

    if result.action == "block":
        raise HTTPException(403, "Content blocked")

    return {"status": "ok"}

Response Format

CheckResponse(
    id="550e8400-e29b-41d4-a716-446655440000",
    safe=False,
    flagged=True,
    action=Action.BLOCK,
    categories=[
        CategoryResult(category="hate_speech", score=0.91, threshold=0.8, triggered=True),
        CategoryResult(category="harassment", score=0.08, threshold=0.8, triggered=False),
    ],
    latency_ms=147,
    policy_id="community-safe",
    provider="hive",
)

Pricing

Plan Price Text Images Videos
Developer Free 10,000/mo 250/mo 100/mo
Starter $29/mo Unlimited 5,000/mo 2,000/mo
Pro $79/mo Unlimited 20,000/mo 10,000/mo
Enterprise $499/mo Unlimited 200,000/mo 100,000/mo

Links

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

vettly-0.1.4.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

vettly-0.1.4-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file vettly-0.1.4.tar.gz.

File metadata

  • Download URL: vettly-0.1.4.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for vettly-0.1.4.tar.gz
Algorithm Hash digest
SHA256 89c64d5f90fbf7d57cff766cf9d80aecd310115533bdd700930b549aff5dafe4
MD5 7d029c490366f756d89d062de7204ebd
BLAKE2b-256 1f91f75d8f448148e48e25ea68fc3976da290d2e5eb621a0bb76c34467184f53

See more details on using hashes here.

File details

Details for the file vettly-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: vettly-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for vettly-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c00bd6b1b0a22afd5d821746b2437b36a248b6261a9aa003cc8583f25dd683e3
MD5 62b076e495d19a198eb4678df79d8c49
BLAKE2b-256 9e9c2d4f31857f88d32f4bae79ca244f9dff23e86985c54741a5ee72edc7e93f

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