Skip to main content

Library with Python models derived from the page package world.opensemantic.lab

Project description

PyPI-Server Coveralls

opensemantic.lab

Python models and controllers for the world.opensemantic.lab page package.

Builds on opensemantic.base (DataToolController, TimeSeriesDatabaseController, archiving, typed read/write).

Overview

  • Auto-generated Pydantic models (v1 and v2): OpcUaServer, OpcUaDataChannel, LaboratoryProcess, Sample, Material, etc.
  • OpcUaServer controller - OPC UA client/server lifecycle with channel subscriptions and data archiving

OpcUaServer controller

Extends DataToolController with OPC UA protocol logic:

from opensemantic import compute_scoped_uuid
from opensemantic.lab.v1 import OpcUaServer, OpcUaDataChannel, OpcUaClientMode
from opensemantic.characteristics.quantitative.v1 import Temperature, Time, TimeUnit
from opensemantic.core.v1 import Label
from uuid import NAMESPACE_URL, uuid5

SERVER_UUID = uuid5(NAMESPACE_URL, "my-server")

server = OpcUaServer(
    uuid=SERVER_UUID,
    name="my_server",
    label=[Label(text="My Server")],
    url="opc.tcp://localhost:4840",
    data_channels=[
        OpcUaDataChannel(
            uuid=compute_scoped_uuid(SERVER_UUID, "ns=2;s=Temperature"),
            node_id="ns=2;s=Temperature",
            name="temperature",
            label=[Label(text="Temperature")],
            opcua_data_type="Float",
            client_mode=OpcUaClientMode.Subscription,
            sampling_interval=Time(value=100, unit=TimeUnit.milli_second),
            refresh_interval=Time(value=500, unit=TimeUnit.milli_second),
            characteristic=Temperature.get_cls_iri(),
        ),
    ],
    auto_archive=True,
)

OPC UA-specific methods

  • run_as_server(params) - start an OPC UA server with value callbacks
  • run_as_client(params) - connect, subscribe to channels, auto-archive
  • read_channel(params) / write_channel(params) - direct channel I/O
  • browse(params) - browse the OPC UA address space
  • stop() - flush archive buffer and disconnect

Channel UUIDs

OpcUaDataChannel requires an explicit UUID. Use compute_scoped_uuid(server_uuid, node_id) from opensemantic to avoid collisions across servers.

Controller fields (runtime only)

url, archive_database, auto_archive, reset_opcua_connection_on_error are controller-only fields. They are stripped from to_json() / to_jsonld() serialization. Set them as runtime config when constructing the controller.

Inherited features

All DataTool features from opensemantic.base work automatically: auto-archive from storage_locations, typed read/write, subobject ID prefixing, channel characteristic warnings. See the opensemantic.base README for details.

LiveDataToolView (Live Dashboard UI)

Extends the base DataToolView with real-time OPC UA streaming via Bokeh.

Features:

  • Archive tab with all base DataToolView features (stacked plots, unit switching, log console)
  • Live tab with Bokeh streaming plots updated via OPC UA subscriptions
  • Per-channel unit conversion for live data
  • Configurable history window, buffer size, and update interval via the live sub-config of LiveDataToolViewConfig
  • Optional URL sync (url_sync=True) persists the selection / units / time window in the browser URL (visible in the address bar of the screenshots below)

Live Demo

Interactive demo: archive view and real-time OPC UA streaming

Archive Tab

Archive view with accumulated OPC UA data

Live Streaming

Real-time OPC UA streaming with stacked Bokeh plots

from opensemantic.base.view import DataToolPlotControlsConfig, UrlConfigMode
from opensemantic.lab.view import (
    LiveConfig,
    LiveDataToolView,
    LiveDataToolViewConfig,
)

view = LiveDataToolView(
    controllers=[ctrl],
    config=LiveDataToolViewConfig(
        lang="en",
        plot=DataToolPlotControlsConfig(auto_fetch=True),
        live=LiveConfig(buffer_size=500, update_interval_ms=500, history_seconds=30),
    ),
    title="Live Dashboard",
    url_sync=True,
    url_mode=UrlConfigMode.PLAIN_KEYS,  # human-readable flattened query params
)
view.servable()

See examples/live_dashboard.py for a full working example with an embedded OPC UA server.

To regenerate the screenshots after UI changes, see docs/generate_screenshots.py.

Examples

See examples/ for complete runnable examples:

  • opc_ua_server.py - define server, store to oold backend, run
  • opc_ua_client.py - load from backend, connect, print archived data
  • opcua_archiving.py - full workflow with auto-archiving and typed read/write
  • live_dashboard.py - live dashboard with embedded OPC UA server

Installation

pip install opensemantic.lab             # models only
pip install opensemantic.lab[controller] # + asyncua, opensemantic.base[controller]
pip install opensemantic.lab[view]       # + opensemantic.base[view]

Testing

pytest tests/test_controller.py

Tests include OPC UA server/client integration (uses asyncua's built-in test server, no external services needed).

For PostgREST-based archiving tests, see the opensemantic.base testing docs - requires a running pgstack instance with TimescaleDB.

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

opensemantic_lab-0.8.1.post1000002004001.tar.gz (5.7 MB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file opensemantic_lab-0.8.1.post1000002004001.tar.gz.

File metadata

File hashes

Hashes for opensemantic_lab-0.8.1.post1000002004001.tar.gz
Algorithm Hash digest
SHA256 1d217057d995a4346e6e2786f8a3773a002b4d39d14a087839c785a52efb322d
MD5 31d9d16f55e2311320aecd077271fdf2
BLAKE2b-256 fd3735aac3e147a1d3d37aedbbfcce93426926480a79803a61a050bf15415c5b

See more details on using hashes here.

File details

Details for the file opensemantic_lab-0.8.1.post1000002004001-py3-none-any.whl.

File metadata

File hashes

Hashes for opensemantic_lab-0.8.1.post1000002004001-py3-none-any.whl
Algorithm Hash digest
SHA256 e613f6585808e0054b93c961d9d2689a6d06a3ccc29171ac1ab795bca3201978
MD5 f6e1500ab2e6c95d3a9d09bc90e2e8a3
BLAKE2b-256 0d70ae4ee133f53acc1af82ad11ea60f68b9e919ef3ecd0a9a92b11d4feff0a9

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