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 callbacksrun_as_client(params)- connect, subscribe to channels, auto-archiveread_channel(params)/write_channel(params)- direct channel I/Obrowse(params)- browse the OPC UA address spacestop()- 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
livesub-config ofLiveDataToolViewConfig - 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)
Interactive demo: archive view and real-time OPC UA streaming
Archive view with accumulated OPC UA data
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, runopc_ua_client.py- load from backend, connect, print archived dataopcua_archiving.py- full workflow with auto-archiving and typed read/writelive_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.
Metadata
Release files for opensemantic.lab 0.8.1.post1000002004003
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| opensemantic_lab-0.8.1.post1000002004003.tar.gz | 5.7 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| opensemantic_lab-0.8.1.post1000002004003-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.8 MB
Release files / opensemantic_lab-0.8.1.post1000002004003.tar.gz
| Download URL | opensemantic_lab-0.8.1.post1000002004003.tar.gz |
|---|---|
| Size | 5.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d0433b36ff5e8e4926341af3839403d48720f0537b49676fc37d770464a24d6
|
|
BLAKE2b-256 checksum How to use checksums |
d0a82c657faf4d2cb8862bef3d17b7a3303faa80033946fcc3438dd992c1a4d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / opensemantic_lab-0.8.1.post1000002004003-py3-none-any.whl
| Download URL | opensemantic_lab-0.8.1.post1000002004003-py3-none-any.whl |
|---|---|
| Size | 51.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e3dafd2429ca9fa43fafcdbcc84e17bf326920c9b10b2c0bf6ee96bac6d2b498
|
|
BLAKE2b-256 checksum How to use checksums |
e036c713aa71a0e356e3be002e77e4d89447c0499a66710a4290e44b7d8c8daa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|