Skip to main content

Python API for Sintela Onyx protobuf

Project description

onyxpublic

Python client library for Sintela Onyx gRPC APIs.

The package currently exposes:

  • AsyncOnyxDevice for connecting to a single device, fetching identification, reading detections, reading system events, and running a background detection stream.
  • Pydantic models such as Detection for 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 with GetIdentification.
  • start_detection_stream(...) is non-blocking and creates a background task. Do not await it.
  • 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.

  • OnyxIdentification contains manufacturer, model, serial number, and fiber metadata.
  • Detection contains normalized detection fields such as timestamps, classification, severity, and position information.
  • SystemEvent contains 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. Includes message, code, reason, and details fields.
  • AuthError: Raised when the server rejects credentials or authorization.
  • ConnectError: Raised for transport-level connection failures. Inspect reason for values such as timeout, connection_refused, or transport_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=True is the default and uses system CAs unless you provide server_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_time passed to get_detections() must be timezone-aware.
  • device.identity is populated after a successful connect().
  • device.is_streaming reports 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


Download files

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

Source Distribution

onyxpublic-0.1.4.tar.gz (57.7 kB view details)

Uploaded Source

Built Distribution

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

onyxpublic-0.1.4-py3-none-any.whl (61.5 kB view details)

Uploaded Python 3

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

Hashes for onyxpublic-0.1.4.tar.gz
Algorithm Hash digest
SHA256 4340b72959e189ef24cf9c0e94adac8a0fc54d2588df2db00e0ab09733e4e45b
MD5 99a6b4f455c938f2fd0a4b6624e3c0f8
BLAKE2b-256 8232ed30c45b1e332581ed656a20d2683ebe3ccf79117e7f5cba74a55ddf611f

See more details on using hashes here.

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

Hashes for onyxpublic-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 95132db3ec40cecb37ebc73afdaea45eeefb94dd65ab11b12e1a5211e3514728
MD5 9e552b7520f03c2dd8a414c4ae6e7528
BLAKE2b-256 c68c9f7f3dd16cd0725f4fade0b38fed59b8d2b41a2d82c3f223edd79274c9e3

See more details on using hashes here.

Supported by

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