Skip to main content

ntt-json-model

Library with model object which is observable and can be serialize and deserialize from json file

Example

With primitive data

from ntt_json_model import *

class TestModel(ModelBase):
    def __init__(self, 
                    nValue: int = 3, 
                    strName: str = "Hello",
                    fTemp: float = 3.1,
                    lstScores: List[int] = []) -> None:
        super().__init__()

        IntegerProperty(self, nValue, "_nValue")
        FloatProperty(self, fTemp, "_fTemp")
        StrProperty(self, strName, "_strName")
        ListProperty(self, lstScores, "_lstScores")

    @property
    def Value(self) -> int:
        return self._nValue.GetValue()

    @Value.setter
    def Value(self, nValue: int) -> None:
        self._nValue.SetValue(nValue)

    @property
    def Temp(self) -> str:
        return self._fTemp.GetValue()

    @Temp.setter
    def Temp(self, fTemp: float) -> None:
        self._fTemp.SetValue(fTemp)
    
    @property
    def Name(self) -> str:
        return self._strName.GetValue()

    @Name.setter
    def Name(self, strName: str) -> None:
        self._strName.SetValue(strName)

    @property
    def Scores(self) -> List[int]:
        return self._lstScores.GetValue()

ModelBase.mSubModels[TestModel.__name__] = TestModel

def PrintIfChanged() -> None:
    print("Model has changed")

model = TestModel()
model.Connect(PrintIfChanged)
model.Temp = 3  # ---> "Model has changed"

print(model.ToDict()) 
# Output:
# {
#     "__class__": "TestModel",
#     "_nValue": 3,
#     "_fTemp": 3.0,
#     "_strName": "Hello",
#     "_lstScores": []
# }

model.FromDict({
    "__class__": "TestModel",
    "_nValue": 3,
    "_fTemp": 3.0,
    "_strName": "Hello",
    "_lstScores": [4, 3]
})

Model Data

class TestModelClass(ModelBase):
    def __init__(self, nScore: int = 4, *args, **kwargs) -> None:
        super().__init__()

        IntegerProperty(self, nScore, "_nScore")
        ModelProperty(self, TestModel(*args, **kwargs), "_mTestModel")

    @property
    def Score(self) -> int:
        return self._nScore.GetValue()

    @Score.setter
    def Score(self, nNewScore: int) -> None:
        self._nScore.SetValue(nNewScore)

    @property
    def TestModel(self) -> TestModel:
        return self._mTestModel.GetValue()

ModelBase.mSubModels[TestModelClass.__name__] = TestModelClass

Model List Data

class TestModelListClass(ModelBase):
    def __init__(self, fScore: float = 8.5) -> None:
        super().__init__()

        FloatProperty(self, fScore, "_fScore")
        ModelListProperty(self, [], "_mModels")
        
    @property
    def Score(self) -> float:
        return self._fScore.GetValue()

    @Score.setter
    def Score(self, fNewScore: float) -> None:
        self._fScore.SetValue(fNewScore)

    @property
    def Models(self) -> List[TestModelClass]:
        return self._mModels.GetValue()

ModelBase.mSubModels[TestModelListClass.__name__] = TestModelListClass

Metadata

Release files for ntt-json-model 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ntt-json-model 1.0.2
File Size Uploaded Provenance Actions
ntt-json-model-1.0.2.tar.gz 8.6 kB Without provenance Details for ntt-json-model-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ntt-json-model 1.0.2
File Interpreter ABI Platform Actions
ntt_json_model-1.0.2-py3-none-any.whl Python 3 none any Details for ntt_json_model-1.0.2-py3-none-any.whl

Total release size: 21.5 kB

Release files / ntt-json-model-1.0.2.tar.gz

Download URL ntt-json-model-1.0.2.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
37e778aec0909748016e21ade850dcee9fd69d1f3e99382d1b010cb2d91b7fa8
BLAKE2b-256 checksum
How to use checksums
8a3f6d14aed687bdccad680be0c4453366e9ff9370cbb04a0f1e5502ebe3e418
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.7

Release files / ntt_json_model-1.0.2-py3-none-any.whl

Download URL ntt_json_model-1.0.2-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88ba87a97d06a64d387c7cae75a63fd2c27974157ab47f5f9b7786d1d8c35840
BLAKE2b-256 checksum
How to use checksums
23d85c2ca5d332968633e54cd03738f80194c9d87b33424ad5f3c5e258e5ea54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.7

Security for ntt-json-model 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page