Metadata-Version: 2.4
Name: messyapi-autopilot
Version: 1.0.0
Summary: Official MessyAPI AutoPilot client: send messy records, get clean data and a receipt back.
License: MIT
Project-URL: Homepage, https://messyapi.com/docs
Keywords: messyapi,autopilot,data-cleaning,etl,ai-guardrails
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# messyapi-autopilot (Python)

Send messy records in. Get clean, scored records back, with a receipt of every change. No dependencies.

```bash
pip install messyapi-autopilot
```

```python
import os
from messyapi_autopilot import AutoPilot

ap = AutoPilot(api_key=os.environ["MESSYAPI_KEY"])  # use a messy_test_ key while experimenting
out = ap.clean([{"name": " ana SOUZA ", "email": "ANA@Example.com ", "phone": "(555) 123-4567"}])
print(out["data"], out["messy_score"], out["receipt"])
```

## API reference

### `AutoPilot(api_key, base_url="https://messyapi.com", max_retries=2, timeout=60)`
Retries 429 / 5xx / network errors, honouring `Retry-After`.

### `ap.clean(records, **options)` → `POST /api/v1/autopilot`
Cleans and returns data. 1 credit per record, max 1,000 per call.

### `ap.preview(records, **options)` → `POST /api/v1/autopilot/preview`
Dry run — returns `proposed_data`.

### Options
| Option | Values | Default | Effect |
|---|---|---|---|
| `mode` | `enforce`, `shadow` | `enforce` | `shadow` returns original data, changes under `shadow.proposed_data` |
| `latency_budget_ms` | 1–30000 | none | Speed limit; `on_error` decides what happens |
| `on_error` | `fail_open`, `fail_closed` | `fail_closed` | `fail_open` passes data through (`degraded: True`, not charged) |
| `agent` | `input`, `output` | off | Check for prompt injection / secrets / personal data |
| `agent_policy` | `flag`, `redact`, `block` | `flag` | Action when the agent check finds something |
| `contract` | name | none | Check cleaned data against a saved data contract |
| `idempotency_key` | str | none | Safe retries — never charged twice |

### Errors
Raises `MessyApiError` with `status`, `code`, `message`, `request_id`, `retry_after`.

### `verify_webhook(raw_body, signature_header, secret)` → `bool`
Checks `X-Messy-Signature` on `autopilot.completed` webhooks (5-minute tolerance).

See `examples/` for cleaning, shadow mode, AI guardrails and a Flask webhook receiver.
