Python API for Sintela Onyx protobuf
Project description
onyxpublic
Python client library for Sintela Onyx gRPC APIs.
The package currently exposes:
AsyncOnyxDevicefor connecting to a single device, fetching identification, reading detections, reading system events, and running a background detection stream.- Pydantic models such as
Detectionfor working with normalized response payloads.
Requirements
- Python 3.11+
- Access to an Onyx device endpoint
- A bearer token
Install
Install the package from PyPI:
uv add onyxpublic-python
Quick Start
Use AsyncOnyxDevice when you want one object representing a single Onyx system.
import asyncio
from datetime import datetime, timedelta, timezone
from onyxpublic import AsyncOnyxDevice
from onyxpublic.errors import OnyxPublicError
async def on_detection(detection) -> None:
print(f"Detection {detection.id}: {detection.classification}")
async def on_stream_error(exc: OnyxPublicError) -> None:
print(type(exc).__name__, exc.reason, exc.message)
async def main() -> None:
device = AsyncOnyxDevice(
"YOUR_TOKEN",
host="127.0.0.1",
port=8181,
using_tls=True,
# server_cert_path="certs/ca.crt", # Optional custom CA bundle
)
try:
await device.connect()
if device.identity is not None:
print("Connected to serial:", device.identity.serial_number)
one_hour_ago = datetime.now(timezone.utc) - timedelta(hours=1)
detections = await device.get_detections(from_time=one_hour_ago)
print(f"Fetched {len(detections)} detections")
system_events = await device.get_system_events()
print(f"Fetched {len(system_events)} system events")
# Starts a background task immediately. This call is not awaited.
device.start_detection_stream(
on_detection=on_detection,
on_error=on_stream_error,
from_seconds_ago=30,
)
await asyncio.sleep(60)
finally:
await device.close()
if __name__ == "__main__":
asyncio.run(main())
An end-to-end sample is also available in example.py.
Connection Behavior
connect()establishes the gRPC channel and immediately validates connectivity withGetIdentification.start_detection_stream(...)is non-blocking and creates a background task. Do notawaitit.close()closes the device channel.- If a unary RPC or detection stream hits a transport-level failure, the library classifies the gRPC error into a stable exception type and resets device state when appropriate. Reconnect explicitly before issuing more calls.
Models
The high-level device API returns Pydantic models from onyxpublic.model.
OnyxIdentificationcontains manufacturer, model, serial number, and fiber metadata.Detectioncontains normalized detection fields such as timestamps, classification, severity, and position information.SystemEventcontains normalized system event fields including level, status, timestamps, and descriptive metadata.
Enum-like protobuf values are normalized during model validation. Detection severity is parsed from enum names, while system event level and status accept enum names or integer values.
Error Handling
The library exposes structured exceptions in onyxpublic.errors:
OnyxPublicError: Base class for library errors. Includesmessage,code,reason, anddetailsfields.AuthError: Raised when the server rejects credentials or authorization.ConnectError: Raised for transport-level connection failures. Inspectreasonfor values such astimeout,connection_refused, ortransport_unavailable.DeviceNotConnectedError: Raised when an operation requires a connected device.EventStreamerAlreadyRunningError: Raised when a second detection stream is started while one is still active.EventStreamerConnectionError: Raised for non-auth, non-transport gRPC failures.
Typical handling pattern:
from onyxpublic.errors import AuthError, ConnectError, OnyxPublicError
try:
await device.connect()
except AuthError:
...
except ConnectError as exc:
print(exc.reason)
except OnyxPublicError as exc:
print(exc.message)
TLS and Authentication
- A bearer token is always required.
using_tls=Trueis the default and uses system CAs unless you provideserver_cert_path.- When
using_tls=True, the client sends the token using gRPC call credentials. - When
using_tls=False, the device API attaches the token as request metadata on individual calls.
Notes
from_timepassed toget_detections()must be timezone-aware.device.identityis populated after a successfulconnect().device.is_streamingreports whether the background detection stream task is still active.
Generated Code
This repository includes generated protobuf and gRPC files under src/onyxpublic/api and src/onyxpublic/common.
To regenerate them:
- Windows:
./scripts/codegen.ps1 - Linux/macOS:
./scripts/codegen.sh
The generation scripts also patch generated imports so both runtime files and .pyi stubs use package-qualified imports such as from onyxpublic.api import onyx_pb2 and from onyxpublic.common import common_pb2.
See scripts/README.md for regeneration prerequisites.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file onyxpublic-0.1.4.tar.gz.
File metadata
- Download URL: onyxpublic-0.1.4.tar.gz
- Upload date:
- Size: 57.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4340b72959e189ef24cf9c0e94adac8a0fc54d2588df2db00e0ab09733e4e45b
|
|
| MD5 |
99a6b4f455c938f2fd0a4b6624e3c0f8
|
|
| BLAKE2b-256 |
8232ed30c45b1e332581ed656a20d2683ebe3ccf79117e7f5cba74a55ddf611f
|
File details
Details for the file onyxpublic-0.1.4-py3-none-any.whl.
File metadata
- Download URL: onyxpublic-0.1.4-py3-none-any.whl
- Upload date:
- Size: 61.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95132db3ec40cecb37ebc73afdaea45eeefb94dd65ab11b12e1a5211e3514728
|
|
| MD5 |
9e552b7520f03c2dd8a414c4ae6e7528
|
|
| BLAKE2b-256 |
c68c9f7f3dd16cd0725f4fade0b38fed59b8d2b41a2d82c3f223edd79274c9e3
|