# AI Box Library

Python library for the NXP Edge AI Industrial Platform.

## Overview

`ai-box-lib` provides thin clients for component-to-component communication:

- `DataCollectorClient` for publishing collector payloads
- `PreProcessorClient` for subscribing collector payloads and publishing features
- `ContextEngineClient` for publishing context messages

## Installation

Install from PyPI:

```bash
pip install ai-box-lib
```

## Quick Start

### 1) Publish data from a data collector

```python
from ai_box_lib.data_collector_client import DataCollectorClient

client = DataCollectorClient[dict]()
client.connect()
client.publish_timestream({"random_number": "42"})
```

### 2) Subscribe and publish from a pre-processor

```python
from ai_box_lib.pre_processor_client import PreProcessorClient

client = PreProcessorClient[dict, dict]()
client.connect()

def handle_raw(message: dict) -> None:
	processed = {"feature_a": [1.0, 2.0, 3.0]}
	client.publish_data(processed)

unsubscribe = client.subscribe_timestream(handle_raw)
```

### 3) Publish context output

```python
from ai_box_lib.context_engine_client import ContextEngineClient

client = ContextEngineClient[dict]()
client.connect()
client.publish_data({"state": "ok"})
```

## API Summary

- `DataCollectorClient.publish_timestream(data)`
- `DataCollectorClient.publish_audio(data)`
- `PreProcessorClient.subscribe_timestream(handler)`
- `PreProcessorClient.subscribe_audio(handler)`
- `PreProcessorClient.publish_data(data)`
- `ContextEngineClient.publish_data(data)`

## Validation and Limits

- Clients must call `connect()` before publish/subscribe operations.
- `DataCollectorClient` validates message keys against `CHANNELS`.
- `PreProcessorClient` validates feature keys and feature shapes against `FEATURES`.
- Maximum publish payload size is 2 MB.

## License

See `LICENSE`.
