onedm


Nameonedm JSON
Version 0.2.2 PyPI version JSON
download
home_pageNone
SummaryCommon data model for IoT and IoT devices
upload_time2024-10-25 13:34:30
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords iot data model
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # OneDM Python library

This Python package is an early work-in-progress to simplify working with
[One Data Model](https://onedm.org/) 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](https://ietf-wg-asdf.github.io/SDF/sdf.html) 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](https://docs.pydantic.dev/) 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:

```python
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:

```python
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:

```python
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)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "onedm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "iot, data model",
    "author": null,
    "author_email": "Christian Sandberg <christiansandberg@me.com>",
    "download_url": "https://files.pythonhosted.org/packages/34/8f/60ebb21fd536b4532a0b4a7612ee75f942b459af01567fc248a13adfdfe9/onedm-0.2.2.tar.gz",
    "platform": null,
    "description": "# OneDM Python library\n\nThis Python package is an early work-in-progress to simplify working with\n[One Data Model](https://onedm.org/) in Python.\n\nSince OneDM is in early stages, this library intends to follow the progress\nas best as it can and should hence be considered unstable.\n\n\n## SDF\n\nCurrently it supports limited loading and generation of\n[SDF](https://ietf-wg-asdf.github.io/SDF/sdf.html) documents.\n\n> The Semantic Definition Format (SDF) is a format for domain experts to use in\n> the creation and maintenance of data and interaction models that describe Things,\n> i.e., physical objects that are available for interaction over a network.\n> An SDF specification describes definitions of SDF Objects/SDF Things and their\n> associated interactions (Events, Actions, Properties), as well as the Data types\n> for the information exchanged in those interactions.\n\nThis library uses [Pydantic](https://docs.pydantic.dev/) to parse, validate,\nand dump model descriptions. The Pydantic models enforce a stricter validation\nthan the current SDF JSON schema where each data type has its own schema.\n\nYou can also validate and coerce input values against your data definitions, as\nwell as generating sdf.Data objects from native Python types!\n\n\n## Examples\n\nLoading an existing SDF document:\n\n```python\nfrom onedm import sdf\n\nloader = sdf.SDFLoader()\nloader.load_file(\"tests/sdf/test.sdf.json\")\ndoc = loader.to_sdf()\n\ndoc.info.title        \n'Example document for SDF (Semantic Definition Format)'\n\ndoc.properties[\"IntegerProperty\"]\n# 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)\n\ndoc.data[\"Integer\"].validate_input(3)\nTraceback (most recent call last):\n  File \"<stdin>\", line 1, in <module>\n  File \"onedm\\sdf\\data.py\", line 129, in validate_input\n    return super().validate_input(input)\n           ^^^^^^^^^^^^^^^^^^^^^^^\n  File \"onedm\\sdf\\data.py\", line 64, in validate_input\n    return SchemaValidator(self.get_pydantic_schema()).validate_python(input)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\npydantic_core._pydantic_core.ValidationError: 1 validation error for constrained-int\n  Input should be a multiple of 2 [type=multiple_of, input_value=3, input_type=int]\n    For further information visit https://errors.pydantic.dev/2.8/v/multiple_of\n```\n\nCreating a new document:\n\n```python\nfrom onedm import sdf\n\ndoc = sdf.Document()\n\ndoc.info.title = \"Generic switch document\"\ndoc.things[\"switch\"] = sdf.Thing(label=\"Generic switch\")\ndoc.things[\"switch\"].actions[\"on\"] = sdf.Action(label=\"Turn on\")\ndoc.things[\"switch\"].properties[\"state\"] = sdf.BooleanProperty()\nprint(doc.to_json())\n\"\"\"\n{\n  \"info\": {\n    \"title\": \"Generic switch document\"\n  },\n{\n  \"sdfThing\": {\n    \"switch\": {\n      \"label\": \"Generic switch\",\n      \"sdfProperty\": {\n        \"state\": {\n          \"type\": \"boolean\"\n        }\n      },\n      \"sdfAction\": {\n        \"on\": {\n          \"label\": \"Turn on\"\n        }\n      }\n    }\n  }\n}\n\"\"\"\n```\n\nGenerating SDF data descriptions from many native Python types:\n\n```python\nfrom onedm.sdf.from_type import data_from_type\n\ndata_from_type(bool | None) \n# BooleanData(label=None, description=None, ref=None, type='boolean', sdf_type=None, nullable=True, const=None, default=None, choices=None)\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Common data model for IoT and IoT devices",
    "version": "0.2.2",
    "project_urls": {
        "Issues": "https://github.com/christiansandberg/onedm/issues",
        "Repository": "https://github.com/christiansandberg/onedm.git"
    },
    "split_keywords": [
        "iot",
        " data model"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06defa876c3dab9c3b95bcb6695bad7b9125fc59d682e6c036ce631162c21928",
                "md5": "1e24cecc6bb7d3a52c47231d37242acc",
                "sha256": "179c8d61fb392e7e1745be51de8cf0c8f8288f03c486dd89a3fc4c6c9b97c4ab"
            },
            "downloads": -1,
            "filename": "onedm-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1e24cecc6bb7d3a52c47231d37242acc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 11984,
            "upload_time": "2024-10-25T13:34:28",
            "upload_time_iso_8601": "2024-10-25T13:34:28.906040Z",
            "url": "https://files.pythonhosted.org/packages/06/de/fa876c3dab9c3b95bcb6695bad7b9125fc59d682e6c036ce631162c21928/onedm-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "348f60ebb21fd536b4532a0b4a7612ee75f942b459af01567fc248a13adfdfe9",
                "md5": "d7b3cbedf1566cd525f8ad68a4d34535",
                "sha256": "29918e2ed384d1e7ae844b224411926e96cfcc614499636e886a336b80050c4e"
            },
            "downloads": -1,
            "filename": "onedm-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d7b3cbedf1566cd525f8ad68a4d34535",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 17691,
            "upload_time": "2024-10-25T13:34:30",
            "upload_time_iso_8601": "2024-10-25T13:34:30.543805Z",
            "url": "https://files.pythonhosted.org/packages/34/8f/60ebb21fd536b4532a0b4a7612ee75f942b459af01567fc248a13adfdfe9/onedm-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-25 13:34:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "christiansandberg",
    "github_project": "onedm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "onedm"
}
        
Elapsed time: 1.49236s