# acta-sql

**Query Veritas Acta receipt DAGs with SQL.**

Flattens [Veritas Acta](https://veritasacta.com) receipt DAGs into queryable DuckDB tables. Built on DuckDB for blazing-fast local analytics. No server required.

## Install

```bash
pip install acta-sql
```

## CLI Usage

```bash
# Load receipts into a local DuckDB file
acta-sql load audit-bundle.json

# Query with SQL
acta-sql query "SELECT tool_name, COUNT(*) FROM receipts GROUP BY tool_name"

# Quick summary
acta-sql summary
```

Example output from `acta-sql summary`:

```
Receipts:     142
Denied:       7
Unique tools: 12
Time range:   2026-03-01T00:00:00Z to 2026-03-27T23:59:59Z
```

## Python API

```python
from acta_sql import load_receipts, create_db, query

receipts = load_receipts("audit-bundle.json")
db = create_db(receipts)
rows = query(db, "SELECT tool_name, decision, COUNT(*) as n FROM receipts GROUP BY tool_name, decision ORDER BY n DESC")
for row in rows:
    print(row)
```

## Database Schema

### `receipts`

| Column | Type |
|--------|------|
| id | VARCHAR (PK) |
| type | VARCHAR |
| tool_name | VARCHAR |
| decision | VARCHAR |
| agent_id | VARCHAR |
| issuer_id | VARCHAR |
| timestamp | VARCHAR |
| policy_hash | VARCHAR |
| signature | VARCHAR |
| raw_json | VARCHAR |

### `edges`

| Column | Type |
|--------|------|
| source_id | VARCHAR |
| target_id | VARCHAR |
| relation | VARCHAR |

### `payloads`

| Column | Type |
|--------|------|
| receipt_id | VARCHAR |
| key | VARCHAR |
| value | VARCHAR |

## Supported Input Formats

- `.json` — A JSON array of receipts, or an object with a `receipts` key
- `.jsonl` — One receipt per line
- Python `list[dict]` — Pass directly to `create_db()`

## License

MIT
