Skip to main content

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 and generation of SDF documents.

The Semantic Definition Format (SDF) is a format for domain experts to use in the creation and maintenance of data and interaction models that describe Things, i.e., physical objects that are available for interaction over a network. 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.

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

loader = sdf.SDFLoader()
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onedm-0.2.3.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

onedm-0.2.3-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file onedm-0.2.3.tar.gz.

File metadata

  • Download URL: onedm-0.2.3.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for onedm-0.2.3.tar.gz
Algorithm Hash digest
SHA256 6a965ef3a369f2faf2bc61c739f8d812f7858c0658e1c75ee552170df6aea04e
MD5 c3256656ab8fe59846651da84c0f475d
BLAKE2b-256 4a9bf0bed8468af39a48ad8a3cbc530bfa59f944f90a07d685816015b38ae164

See more details on using hashes here.

Provenance

The following attestation bundles were made for onedm-0.2.3.tar.gz:

Publisher: python-publish.yml on christiansandberg/onedm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onedm-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: onedm-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for onedm-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c079b4ebe94f3d7aa78ef5ea8b858956dde3c79b59040c06aba216ae0eb2c8ea
MD5 f0910f6dab65f3189d0ab0f6190e32a8
BLAKE2b-256 77a6c4d701d92689039d76d5c8b8aeefba2ba93eba51b6731bdb9e99f07f6fcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for onedm-0.2.3-py3-none-any.whl:

Publisher: python-publish.yml on christiansandberg/onedm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page