Skip to main content

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 data collector payloads
  • PreProcessorClient for subscribing data collector payloads and publishing features
  • ContextEngineClient for publishing context messages
  • ChannelClient for generic pub/sub communication between any components

Installation

Install from PyPI:

pip install ai-box-lib

Quick Start

1) Publish data from a data collector

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

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 and subscribe to context data

from ai_box_lib.context_engine_client import ContextEngineClient

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

In a multi-asset setup, a single context engine is often responsible for all assets. Pass custom_asset_id to publish to a different asset's context engine topic:

client.publish_data({"state": "ok"}, custom_asset_id="asset-abc123")
from ai_box_lib.context_engine_client import ContextEngineClient
client = ContextEngineClient[dict]()
client.connect()
client.subscribe()

client.context  # Access the latest context value at any time

def handle_context(message: dict) -> None:
	print(f"Context update: {message}")

client.subscribe(handle_context) # Subscribe with a handler to receive real-time updates

Optionally you can pass custom_asset_id to subscribe to a Context Engine on a different asset, as long as it's connected to the same Box.

4) Communicate over a generic channel

A channel lets any two components exchange messages without being tied to a specific pipeline stage. You define the channel by providing a channel_id string. Both publisher and subscriber must use the same channel_id.

Messages are delivered on the topic {asset_id}/channel/{channel_id}.

Publisher:

from ai_box_lib.channel_client import ChannelClient

client: ChannelClient[None, dict] = ChannelClient("my-alerts")
client.connect()
client.publish({"severity": "high", "value": 42.0})

Subscriber:

from ai_box_lib.channel_client import ChannelClient

client: ChannelClient[dict, None] = ChannelClient("my-alerts")
client.connect()

def handle_alert(message: dict) -> None:
    print(f"Alert received: {message}")

unsubscribe = client.subscribe(handle_alert)
# call unsubscribe() when done

A single client instance can both publish and subscribe on the same channel.

Correlation IDs

Every message carries a correlation id so you can trace one piece of data through the pipeline (e.g. link an ML result back to its source frame). It is minted automatically at the origin and forwarded automatically when you publish from inside a subscription handler — no extra code needed.

Read the id of the message being handled with current_correlation_id():

def handle_raw(message: dict) -> None:
    frame_id = client.current_correlation_id()
    client.publish_data(process(message))  # inherits frame_id automatically

Automatic forwarding only works when you publish from within the handler. If you publish later — from another thread, a timer, or an external trigger such as an API callback — capture the id and pass it back explicitly. Every publish* method accepts an optional correlation_id:

client.publish_data(process(message), correlation_id=frame_id)

API Summary

All clients must call connect() before any publish or subscribe operation.

  • DataCollectorClient.connect()
  • DataCollectorClient.publish_timestream(data, correlation_id?)
  • DataCollectorClient.publish_audio(data, correlation_id?)
  • DataCollectorClient.publish_image(data, correlation_id?)
  • PreProcessorClient.connect()
  • PreProcessorClient.subscribe_timestream(handler)
  • PreProcessorClient.subscribe_audio(handler)
  • PreProcessorClient.subscribe_image(handler)
  • PreProcessorClient.publish_data(data, correlation_id?)
  • ContextEngineClient.connect()
  • ContextEngineClient.publish_data(data, custom_asset_id?, correlation_id?)
  • ContextEngineClient.subscribe(handler?, custom_asset_id?)
  • ContextEngineClient.context — latest received context value (read-only)
  • ChannelClient(channel_id).connect()
  • ChannelClient(channel_id).publish(data, correlation_id?)
  • ChannelClient(channel_id).subscribe(handler)
  • current_correlation_id() — id of the message currently being handled (any client; None outside a handler)

Validation and Limits

  • DataCollectorClient validates message keys against CHANNELS.
  • PreProcessorClient validates feature keys and feature shapes against FEATURES.
  • Maximum publish payload size is 2 MB.

License

BSD-3-Clause. See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_box_lib-1.2.7.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_box_lib-1.2.7-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file ai_box_lib-1.2.7.tar.gz.

File metadata

  • Download URL: ai_box_lib-1.2.7.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ai_box_lib-1.2.7.tar.gz
Algorithm Hash digest
SHA256 0cb78e493fb2189fc09cb4347feef4a4a0342a1f6811ce25056e3760fd0db5e9
MD5 090f45b88b1d5af6af3d53cdabfa6d7e
BLAKE2b-256 6909eea7be5dd5f29a949c9f842d0a4afaf338aa8496bf6c167f716c8801f9b3

See more details on using hashes here.

File details

Details for the file ai_box_lib-1.2.7-py3-none-any.whl.

File metadata

  • Download URL: ai_box_lib-1.2.7-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ai_box_lib-1.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8a32ff92e57d7ef3b5e8483f0f7302dd4ac37bfe528f2cbf45498f9f32f3ddab
MD5 3934da48b0c551dff46781639acfdf3c
BLAKE2b-256 ef4d6b0b8651c1ff52883fc8010bad9517c3a0aaa321001fe483e5774477b738

See more details on using hashes here.

Release history Release notifications | RSS feed

1.7.0

2 files

1.6.1

2 files

1.6.0

2 files

1.4.0

2 files

1.3.0

2 files

This release

1.2.7 This release

2 files

1.2.6

2 files

1.2.5

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.3

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page