Library with Python models derived from the page package world.opensemantic.base
Project description
opensemantic.base
Python models and controllers for the world.opensemantic.base page package.
Builds on oold-python (BaseController, LinkedBaseModel, cast(), _types registry) and opensemantic (OswBaseModel, compute_scoped_uuid).
Overview
- Auto-generated Pydantic models (v1 and v2): Database, WebService, DataTool, DataChannel, Person, Organization, etc.
- DataToolController - generic controller for any DataTool
- TimeSeriesDatabaseController - SQLite and PostgREST backends for time series storage
Architecture
opensemantic.base/
_model.py # auto-generated v2 Pydantic models (DO NOT EDIT)
_controller_mixin.py # DataToolMixin, TimeSeriesDatabaseController mixins
_controller.py # v2 controllers
__init__.py # re-exports model + controller classes
v1/ # same structure for Pydantic v1
DataToolController
Extends DataTool with channel management, subdevice traversal, and data archiving.
from opensemantic.base import DataToolController
tool = DataToolController(
name="sensor",
label=[...],
data_channels=[ch1, ch2],
storage_locations=[db],
auto_archive=True, # auto-creates archive DB from storage_locations[0]
)
tool.get_all_channels() # recursive across subdevices
tool.get_channel_owner(ch) # find which device owns a channel
tool.to_json() # only model fields (controller fields stripped)
Auto-archive from storage_locations
When auto_archive=True and no explicit archive_database is set, the controller auto-creates a LocalTimeSeriesDatabaseController from the first storage_locations entry (resolved via oold backend).
Typed read/write
Channels with a characteristic IRI enable typed serialization:
# Write: converts to base unit, strips defaults for compact storage
await tool.store_typed_data(DataToolMixin.StoreTypedDataParams(
tool_osw_id=tool.get_osw_id(),
rows=[DataToolMixin.TypedDataRow(ts=now, channel=ch, value=Temperature(value=300.0))],
))
# Read: resolves characteristic class via oold's _types registry
results = await tool.read_typed_data(DataToolMixin.ReadTypedDataParams(
tool_osw_id=tool.get_osw_id(), channel=ch,
))
# results[0] is a Temperature instance with defaults restored
Subobject ID auto-computation
Inline subobject osw_id fields are auto-prefixed with the parent's osw_id:
Parent: OSW<parent_uuid>
Channel: OSW<parent_uuid>#OSW<channel_uuid>
Fields with range in json_schema_extra are references to separate entities and are not prefixed.
Unloaded characteristic warning
On init, DataToolController checks if channel characteristic IRIs are present in oold's _types registry. Missing entries produce a warning with guidance to import the corresponding package.
TimeSeriesDatabaseController
Abstract base for time series storage, with SQLite and PostgREST implementations.
from opensemantic.base import LocalTimeSeriesDatabaseController
db = LocalTimeSeriesDatabaseController(name="archive", label=[...], db_path="./data.sqlite")
await db.create_tool(params)
await db.write_tool_channel_raw(params)
await db.read_tool_channel_raw(params)
DataToolView (Dashboard UI)
Interactive dashboard for visualizing archived time series data from DataToolControllers.
Features:
- Wunderbaum TreeGrid for channel selection with characteristic metadata
- Stacked Bokeh plots grouped by characteristic (temperature, pressure, etc.)
- Unit conversion via dropdown (e.g. K to C, Pa to hPa)
- Composite channel splitting (e.g. AirQuality into temperature + pressure sub-plots)
- Text channel log console with timestamped entries
- Configurable via JsonEditor (grouping, auto-fetch, row limit, cache)
Interactive demo: channel selection, plotting, unit switching
Channel selection with stacked plots grouped by characteristic
Unit conversion via dropdown (K to C)
Text channel log console with timestamped entries
from opensemantic.base.view import DataToolView
from opensemantic.base.view._config import DashboardConfig, PlotConfig
view = DataToolView(
controllers=[ctrl],
config=DashboardConfig(lang="en", plot=PlotConfig(auto_fetch=True)),
title="My Dashboard",
)
view.servable() # for panel serve
See examples/datatool_dashboard.py for a full working example.
Installation
pip install opensemantic.base # models only
pip install opensemantic.base[controller] # + aiosqlite, postgrest
pip install opensemantic.base[view] # + panel, bokeh, panelini, pint
Testing
pytest tests/test_controller.py
PostgREST integration tests require a running pgstack instance. To enable them:
- Start pgstack:
docker compose -f docker-compose.yml -f docker-compose.example-tsdb.override.yml up -d - Copy
tests/.env.exampletotests/.envand fill inTEST_PGRST_URLandTEST_PGRST_JWT_SECRET - Run tests - PostgREST tests are skipped unless both env vars are set
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_base-0.42.8.post1000002003000.tar.gz.
File metadata
- Download URL: opensemantic_base-0.42.8.post1000002003000.tar.gz
- Upload date:
- Size: 5.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
524d9b3a9a9fd99d834c7c19892b2e7b74e1eabb53930bf5129253feb300c2d1
|
|
| MD5 |
43b8d0a09bd51067d4fe6e201ce94db8
|
|
| BLAKE2b-256 |
82389d514b9943d4b06901005a33ee60cda57190f85962503bd9e59c6ca3a2b2
|
File details
Details for the file opensemantic_base-0.42.8.post1000002003000-py3-none-any.whl.
File metadata
- Download URL: opensemantic_base-0.42.8.post1000002003000-py3-none-any.whl
- Upload date:
- Size: 134.6 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 |
2aa10d635023f52c532fb8ea357bf0ba87c6d699be1fadd0512e52d386a25715
|
|
| MD5 |
ca04efc19a5c0842bd5b53fbeb4fd168
|
|
| BLAKE2b-256 |
26a8a732fd4f148ef98c101d78ceae4c301900b32894eb646cee2cb3233e3e50
|