# Loopuman Python SDK

Official Python SDK for Loopuman - The Human Layer for AI.

## Installation
```bash
pip install loopuman
```

Or install from source:
```bash
pip install requests
cp loopuman.py your_project/
```

## Quick Start
```python
from loopuman import Loopuman, create_rlhf_comparisons

# Initialize
client = Loopuman(api_key="your_api_key")

# Create RLHF comparison tasks
comparisons = [
    ("Response A", "Response B"),
    ("Another A", "Another B"),
]

batch = create_rlhf_comparisons(client, comparisons)
print(f"Batch ID: {batch['batch_id']}")

# Check status
status = client.get_batch_status(batch['batch_id'])
print(f"Progress: {status['completion_percentage']}%")

# Get results
results = client.get_batch_results(batch['batch_id'])
for r in results['results']:
    print(f"Task {r['external_id']}: {r['content']}")
```

## Webhook Handler
```python
from flask import Flask, request
import hmac
import hashlib

app = Flask(__name__)
WEBHOOK_SECRET = "your_webhook_secret"

@app.route('/loopuman/webhook', methods=['POST'])
def handle_webhook():
    # Verify signature
    signature = request.headers.get('X-Loopuman-Signature', '')
    expected = 'sha256=' + hmac.new(
        WEBHOOK_SECRET.encode(),
        request.data,
        hashlib.sha256
    ).hexdigest()
    
    if not hmac.compare_digest(signature, expected):
        return 'Invalid signature', 401
    
    event = request.json
    
    if event['event'] == 'task.approved':
        task_id = event['data']['task_id']
        content = event['data']['submission']['content']
        # Process the completed task
        print(f"Task {task_id} completed: {content}")
    
    return 'OK', 200
```

## Support

- Email: enterprise@loopuman.com
- Docs: https://docs.loopuman.com
