Metadata-Version: 2.4
Name: cqnce-sdk
Version: 0.1.2
Summary: Official Python SDK for cQnce
Author: cQnce
License: MIT
Project-URL: Homepage, https://github.com/cqnce-app/cqnce-sdk
Project-URL: Repository, https://github.com/cqnce-app/cqnce-sdk
Keywords: cqnce,sdk,auth,workflow
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# cqnce-sdk — Python

Official Python SDK for [cQnce](https://cqnce.app) — human-in-the-loop authorization for AI agents and automated workflows.

## Installation

```bash
pip install cqnce-sdk
```

Requires Python 3.9+. No external dependencies.

## Quick start

```python
from cqnce_sdk import CqnceClient

client = CqnceClient(
    base_url="https://api.cqnce.app",
    project_api_key="YOUR_API_KEY",
)

# Submit a request and wait for human approval (blocking)
result = client.submit_and_wait(
    payload={"action": "delete_user", "userId": "123"},
)

print(result["status"])  # APPROVED | REJECTED | EXPIRED | CANCELLED
```

## Polling options

```python
result = client.submit_and_wait(
    payload={"action": "deploy", "env": "production"},
    interval_seconds=3,    # poll every 3s (default 2s)
    timeout_seconds=300,   # give up after 5 min (default 2 min)
)
```

## Step-by-step (submit + poll separately)

```python
request_id = client.submit_request_and_get_id(
    payload={"action": "delete_user", "userId": "123"}
)

result = client.poll_until_resolved(
    request_id,
    on_resolved=lambda status: print("Resolved:", status["status"]),
    interval_seconds=3,
    timeout_seconds=300,
)
```

## Background polling (non-blocking)

```python
thread = client.poll_until_resolved_background(
    request_id,
    on_resolved=lambda status: print("Resolved:", status["status"]),
    on_timeout=lambda: print("Timed out!"),
    interval_seconds=3,
    timeout_seconds=300,
)

print("doing other work...")
thread.join()  # optional
```

## Callback signature verification

```python
from cqnce_sdk import CallbackVerifier

is_valid = CallbackVerifier.verify(
    raw_body,           # bytes
    signature_header,   # value of X-cQnce-Signature header
    "YOUR_CALLBACK_SECRET",
)
```

## Request-based routing

```python
result = client.submit_and_wait(
    payload={"action": "payment", "amount": 500},
    routing_rule_id="rule-uuid-here",
    routing_mode="SERIAL",
)
```
