{"id":19665218,"url":"https://github.com/alttch/smartobject","last_synced_at":"2025-04-28T22:31:03.993Z","repository":{"id":57468584,"uuid":"222804464","full_name":"alttch/smartobject","owner":"alttch","description":"Simple, powerful Python object manipulation library","archived":false,"fork":false,"pushed_at":"2020-03-04T02:43:21.000Z","size":125,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T11:24:12.617Z","etag":null,"topics":["cbor","iiot","iot","iot-objects","json","messagepack","object","orm","python3","rdbms","redis","sql","sqlalchemy","storage","sync","yaml"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alttch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-19T22:46:00.000Z","updated_at":"2024-04-16T01:05:00.000Z","dependencies_parsed_at":"2022-09-19T11:51:20.138Z","dependency_job_id":null,"html_url":"https://github.com/alttch/smartobject","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Fsmartobject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Fsmartobject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Fsmartobject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Fsmartobject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alttch","download_url":"https://codeload.github.com/alttch/smartobject/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251397576,"owners_count":21583034,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cbor","iiot","iot","iot-objects","json","messagepack","object","orm","python3","rdbms","redis","sql","sqlalchemy","storage","sync","yaml"],"created_at":"2024-11-11T16:21:38.087Z","updated_at":"2025-04-28T22:31:03.475Z","avatar_url":"https://github.com/alttch.png","language":"Python","readme":"# SmartObject\n\n[SmartObject](https://github.com/alttch/smartobject) is a library to easily\nmanipulate object attributes with the API commands, store and synchronize\nobject data.\n\nSmartObject is designed to quickly build IoT applications, but can be used in\nany other applications, which require combining local and distributed object\nstorages and changing object properties via external API calls, automatically\nvalidating incoming data.\n\n\u003cimg src=\"https://img.shields.io/pypi/v/smartobject.svg\" /\u003e \u003cimg src=\"https://img.shields.io/badge/license-MIT-green\" /\u003e \u003cimg src=\"https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8-blue.svg\" /\u003e\n\nMapped object attributes (called properties) can be automatically validated,\nsaved, loaded, serialized and synchronized with the external services.\n\nSmartObject looks like ORM, but it's different from ORM: object properties can\nbe stored in storages of different type and combined together into a single\ndata object.\n\nSmartObject has built-in storage engines for files (JSON, YAML, MessagePack and\nCBOR) and databases: RDBMS via SQLAlchemy (can store objects) and Redis (can\nhandle external properties only).\n\nProperty values are automatically processed, validated and synchronized with\nexternal services if required.\n\nNote: all SmartObject methods are thread-safe (at least they should be :)\n\n## Example:\n\nYou have a team of people with heart-rate sensors. Data for each person is\nstored in local JSON files, heartbeat is stored in Redis database. How to\nimplement this with SmartObject? Just a few lines of code:\n\n```python\nimport smartobject\n\n\nclass Person(smartobject.SmartObject):\n\n    def __init__(self, name):\n        self.name = name\n        self.load_property_map('person.yml')\n        self.apply_property_map()\n\n\nsmartobject.config.storage_dir = 'data'\n\nsmartobject.define_storage(smartobject.JSONStorage())\nsmartobject.define_storage(smartobject.RedisStorage(), 'r1')\n\npeople = smartobject.SmartObjectFactory(Person)\n\n# create objects with factory\npeople.create(name='John')\npeople.create(name='Jane')\n\n# create object manually\njack = Person('Jack')\n\n# you can set a single prop\npeople.set_prop('John', 'sex', 'male')\npeople.set_prop('Jane', 'sex', 'female')\n# or multiple props with dict\n# heartbeat value is automatically written to Redis\njack.set_prop({'sex': 'male', 'heartbeat': 100})\n\n# print object info (name and sex only)\nfrom pprint import pprint\npprint(people.serialize('Jane', mode='info'))\n\npeople.save()\njack.save()\n\n# clear Jack's sex\njack.set_prop('sex', None)\n# load it back\njack.load()\n\n# add Jack to factory\npeople.create(obj=jack)\n\n# heartbeat value is automatically read from Redis\nprint('Heartbeat of Jack is: {}'.format(people.get('Jack').heartbeat))\n\n```\n\nThe file *person.yml* is a property map for the *Person* object. It can be\nloaded from the external YAML file or specified directly, as Python dict.\n\nThe map for the above example looks like:\n\n```yaml\nname:\n    pk: true\n    serialize: info\nsex:\n    type: str\n    choices:\n        - null\n        - male\n        - female\n    store: true\n    serialize: info\nheartbeat:\n    type: float\n    external: true\n    store: r1\n\n```\n\nPretty simple, isn't it? You define a map, SmartObject does the job!\n\n## Install\n\n```shell\npip3 install smartobject\n```\n\n## Documentation\n\nFull documentation is available at https://smartobject.readthedocs.io/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falttch%2Fsmartobject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falttch%2Fsmartobject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falttch%2Fsmartobject/lists"}