Library with Python models derived from the page package world.opensemantic.lab
Project description
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.
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/write
Installation
pip install opensemantic.lab # models only
pip install opensemantic.lab[controller] # + asyncua, opensemantic.base[controller]
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
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 opensemantic_lab-0.7.0.post1000002003001.tar.gz.
File metadata
- Download URL: opensemantic_lab-0.7.0.post1000002003001.tar.gz
- Upload date:
- Size: 70.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4ea61006eb5714fbe348f2bd7f489de7a26cde6350a629e4290a12685a22262
|
|
| MD5 |
4148768c0f062c9aa3253166d71255c2
|
|
| BLAKE2b-256 |
7e7bbe8026974b36b3cb44358dede951839e6520ef4281cf26adc3e348959c8a
|
File details
Details for the file opensemantic_lab-0.7.0.post1000002003001-py3-none-any.whl.
File metadata
- Download URL: opensemantic_lab-0.7.0.post1000002003001-py3-none-any.whl
- Upload date:
- Size: 46.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d44b8abe569d55d0bed4d57802f7decd274ff6be7923dc6b30ec19995d70302
|
|
| MD5 |
74dd32dba1e0edbcc5113f040ec2e510
|
|
| BLAKE2b-256 |
c9237b40180b2d4700d445f51fb304dd56bb7a8f3f89f0b064d65723b32da467
|