Common data model for IoT and IoT devices
Project description
OneDM Python library
This Python package is an early work-in-progress to simplify working with One Data Model in Python.
Since OneDM is in early stages, this library intends to follow the progress as best as it can and should hence be considered unstable.
SDF
Currently it supports limited loading, resolving, and generation of SDF documents as specified in the to-be-published RFC 9880.
The Semantic Definition Format (SDF) is concerned with Things, namely physical objects that are available for interaction over a network. SDF is a format for domain experts to use in the creation and maintenance of data and interaction models that describe Things. An SDF specification describes definitions of SDF Objects/SDF Things and their associated interactions (Events, Actions, Properties), as well as the Data types for the information exchanged in those interactions. Tools convert this format to database formats and other serializations as needed.
This library uses Pydantic to parse, validate, and dump model descriptions. The Pydantic models enforce a stricter validation than the current SDF JSON schema where each data type has its own schema.
You can also validate and coerce input values against your data definitions, as well as generating sdf.Data objects from native Python types!
Examples
Loading an existing SDF document:
from onedm import sdf
from onedm.sdf.registry import FileBasedRegistry
# Create a registry for resolving global references.
# This will scan for local .sdf.json files, but you can also implement
# other strategies.
registry = FileBasedRegistry(".")
# Convenience class for loading, resolving, and parsing
loader = sdf.SDFLoader(registry)
loader.load_file("tests/sdf/test.sdf.json")
doc = loader.to_sdf()
doc.info.title
'Example document for SDF (Semantic Definition Format)'
doc.properties["IntegerProperty"]
# IntegerProperty(label='Example integer', description=None, ref=None, type='integer', sdf_type=None, nullable=False, const=None, default=None, choices=None, unit=None, minimum=-2, maximum=2, exclusive_minimum=None, exclusive_maximum=None, multiple_of=2, observable=True, readable=True, writable=True, sdf_required=None)
doc.data["Integer"].validate_input(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "onedm\sdf\data.py", line 129, in validate_input
return super().validate_input(input)
^^^^^^^^^^^^^^^^^^^^^^^
File "onedm\sdf\data.py", line 64, in validate_input
return SchemaValidator(self.get_pydantic_schema()).validate_python(input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for constrained-int
Input should be a multiple of 2 [type=multiple_of, input_value=3, input_type=int]
For further information visit https://errors.pydantic.dev/2.8/v/multiple_of
Creating a new document:
from onedm import sdf
doc = sdf.Document()
doc.info.title = "Generic switch document"
doc.things["switch"] = sdf.Thing(label="Generic switch")
doc.things["switch"].actions["on"] = sdf.Action(label="Turn on")
doc.things["switch"].properties["state"] = sdf.BooleanProperty()
print(doc.to_json())
"""
{
"info": {
"title": "Generic switch document"
},
{
"sdfThing": {
"switch": {
"label": "Generic switch",
"sdfProperty": {
"state": {
"type": "boolean"
}
},
"sdfAction": {
"on": {
"label": "Turn on"
}
}
}
}
}
"""
Generating SDF data descriptions from many native Python types:
from onedm.sdf.from_type import data_from_type
data_from_type(bool | None)
# BooleanData(label=None, description=None, ref=None, type='boolean', sdf_type=None, nullable=True, const=None, default=None, choices=None)
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 onedm-0.3.1.tar.gz.
File metadata
- Download URL: onedm-0.3.1.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff94af2ef94948d09684c94bf60c4c5aa2e793d21ee64ffa76eb539877b73931
|
|
| MD5 |
950bdf3386167c4886aa4d280c80bcd1
|
|
| BLAKE2b-256 |
d52d19a91c6df4c8188167c7c32b41394bc8c53f4c4355fda6b655823ac9d74f
|
Provenance
The following attestation bundles were made for onedm-0.3.1.tar.gz:
Publisher:
python-publish.yml on christiansandberg/onedm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onedm-0.3.1.tar.gz -
Subject digest:
ff94af2ef94948d09684c94bf60c4c5aa2e793d21ee64ffa76eb539877b73931 - Sigstore transparency entry: 781209686
- Sigstore integration time:
-
Permalink:
christiansandberg/onedm@54b201a68e3800a8e168549f993ff7d62cc428da -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/christiansandberg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@54b201a68e3800a8e168549f993ff7d62cc428da -
Trigger Event:
release
-
Statement type:
File details
Details for the file onedm-0.3.1-py3-none-any.whl.
File metadata
- Download URL: onedm-0.3.1-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9c47605f6b87dfd64d97c4269661e953989aa50e3a5e27a11b6120a3f38f1cf
|
|
| MD5 |
2cc633198a43991ffdb7010c4fb0792c
|
|
| BLAKE2b-256 |
e9e5fe99d40d474dbd940ecc4ddd4bc219e072b5eaae9f8cfa53639587a98841
|
Provenance
The following attestation bundles were made for onedm-0.3.1-py3-none-any.whl:
Publisher:
python-publish.yml on christiansandberg/onedm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onedm-0.3.1-py3-none-any.whl -
Subject digest:
e9c47605f6b87dfd64d97c4269661e953989aa50e3a5e27a11b6120a3f38f1cf - Sigstore transparency entry: 781209688
- Sigstore integration time:
-
Permalink:
christiansandberg/onedm@54b201a68e3800a8e168549f993ff7d62cc428da -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/christiansandberg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@54b201a68e3800a8e168549f993ff7d62cc428da -
Trigger Event:
release
-
Statement type: