-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39b4f4f
commit ad753e8
Showing
17 changed files
with
123 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,67 @@ | ||
# sdf-utils | ||
# OneDM Python library | ||
|
||
[Semantic Definition Format (SDF) for Data and Interactions of Things](https://ietf-wg-asdf.github.io/SDF/sdf.html) | ||
This Python package is an early work-in-progress to simplify working with | ||
[One Data Model](https://onedm.org/) in Python. | ||
|
||
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. | ||
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. | ||
|
||
|
||
## 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(observable=True, readable=True, writable=True, label='Example integer', description=None, ref=None, required=[], type=<DataType.INTEGER: 'integer'>, sdf_type=None, nullable=True, const=2, unit=None, minimum=-2, maximum=2, exclusive_minimum=None, exclusive_maximum=None, multiple_of=2, format=None, choices=None, default=None) | ||
``` | ||
|
||
Creating a new document: | ||
|
||
``` | ||
>>> from onedm import sdf | ||
>>> doc = sdf.SDF() | ||
>>> doc.things["switch"] = sdf.Thing(label="Generic switch") | ||
>>> doc.things["switch"].actions["on"] = sdf.Action(label="Turn on") | ||
>>> print(doc.to_json()) | ||
{ | ||
"sdfThing": { | ||
"switch": { | ||
"label": "Generic switch", | ||
"sdfAction": { | ||
"on": { | ||
"label": "Turn on" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` |
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from pathlib import Path | ||
import pytest | ||
|
||
import sdf | ||
from onedm import sdf | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import sdf | ||
from onedm import sdf | ||
|
||
|
||
def test_integer_data(test_model: sdf.SDF): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
import tempfile | ||
|
||
import pytest | ||
import sdf | ||
from onedm import sdf | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import sdf | ||
from onedm import sdf | ||
|
||
|
||
def test_integer_property(test_model: sdf.SDF): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import sdf | ||
from onedm import sdf | ||
|
||
|
||
def test_reference(test_model: sdf.SDF): | ||
|