Name | pyobjict JSON |
Version |
1.1.12
JSON |
| download |
home_page | |
Summary | A Python dict that supports attribute-style access as well as hierarchical keys, JSON serialization, ZIP compression, and more. |
upload_time | 2023-01-11 20:54:07 |
maintainer | |
docs_url | None |
author | Ian Starnes |
requires_python | >=3.7,<4.0 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
![](https://github.com/311labs/objict/workflows/tests/badge.svg)
## Turn a dict into an Object or objict!
Based on uberdict(https://github.com/eukaryote/uberdict)
## Installation
```
pip install pyobjict
```
### Some Differences:
* Support for to/from JSON
* Support for to/from XML
* Support for to/from ZIP compression (base64)
* Support to/from file
* When an attribute is not found it returns None instead of raising an Error
* Support for .get("a.b.c")
* Support for delta between to objicts (obj.changes())
* Will automatically handle key conversion from "a.b.c" to "a -> b -> c" creation
## Simple to use!
```python
>>> from objict import objict
>>> d1 = objict(name="John", age=24)
>>> d1
{'name': 'John', 'age': 24}
>>> d1.name
'John'
>>> d1.age
24
>>> d1.gender = "male"
>>> d1
{'name': 'John', 'age': 24, 'gender': 'male'}
>>> d1.gender
'male'
>>> import datetime
>>> d1.dob = datetime.datetime(1985, 5, 2)
>>> d1.dob
datetime.datetime(1985, 5, 2, 0, 0)
>>> d1.toJSON()
{'name': 'John', 'age': 24, 'gender': 'male', 'dob': 483865200.0}
>>> d1.save("test1.json")
>>> d2 = objict.fromFile("test1.json")
>>> d2
{'name': 'John', 'age': 24, 'gender': 'male', 'dob': 483865200.0}
>>> d2.toXML()
'<name>John</name><age>24</age><gender>male</gender><dob>483865200.0</dob>'
>>> d3 = objict(user1=d2)
>>> d3.user2 = objict(name="Jenny", age=27)
>>> d3
{'user1': {'name': 'John', 'age': 24, 'gender': 'male', 'dob': 483865200.0}, 'user2': {'name': 'Jenny', 'age': 27}}
>>> d3.toXML()
'<user1><name>John</name><age>24</age><gender>male</gender><dob>483865200.0</dob></user1><user2><name>Jenny</name><age>27</age></user2>'
>>> d3.toJSON(True)
'{\n "user1": {\n "name": "John",\n "age": 24,\n "gender": "male",\n "dob": 483865200.0\n },\n "user2": {\n "name": "Jenny",\n "age": 27\n }\n}'
>>> print(d3.toJSON(True))
{
"user1": {
"name": "John",
"age": 24,
"gender": "male",
"dob": 483865200.0
},
"user2": {
"name": "Jenny",
"age": 27
}
}
>>> d3.toZIP()
b'x\x9c\xab\xe6R\x00\x02\xa5\xd2\xe2\xd4"C%+\x85j0\x17,\x94\x97\x98\x9b\n\x14Q\xf2\xca\xcf\xc8S\xd2A\x88\'\xa6\x83\x84\x8dL\x90\x84\xd2S\xf3RR\x8b@\x8as\x13sR\x91\x15\xa7\xe4\'\x01\x85M,\x8c-\xccL\x8d\x0c\x0c\xf4\x0c\xc0R\xb5:\x08[\x8dp\xd8\x9a\x9a\x97W\x89\xc5Zs\x88\x01\\\xb5\x00^\x1c\'I'
>>> dz = d3.toZIP()
>>> d4 = objict.fromZIP(dz)
>>> d4
{'user1': {'name': 'John', 'age': 24, 'gender': 'male', 'dob': 483865200.0}, 'user2': {'name': 'Jenny', 'age': 27}}
>>> d5 = d4.copy()
>>> d5.user1.name
'John'
>>> d5.user1.name = "Jim"
>>> d5
{'user1': {'name': 'Jim', 'age': 24, 'gender': 'male', 'dob': 483865200.0}, 'user2': {'name': 'Jenny', 'age': 27}}
>>> d5.changes(d4)
{'user1': {'name': 'John'}}
```
Raw data
{
"_id": null,
"home_page": "",
"name": "pyobjict",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Ian Starnes",
"author_email": "ians@311labs.com",
"download_url": "https://files.pythonhosted.org/packages/31/f0/39cb06da1ee07688317c5631444a45d5e2b2f25c4443aa1944ec86c4b821/pyobjict-1.1.12.tar.gz",
"platform": null,
"description": "![](https://github.com/311labs/objict/workflows/tests/badge.svg)\n\n## Turn a dict into an Object or objict!\n\nBased on uberdict(https://github.com/eukaryote/uberdict)\n\n## Installation\n\n```\npip install pyobjict\n```\n\n\n### Some Differences:\n\n * Support for to/from JSON\n * Support for to/from XML\n * Support for to/from ZIP compression (base64)\n * Support to/from file\n * When an attribute is not found it returns None instead of raising an Error\n * Support for .get(\"a.b.c\")\n * Support for delta between to objicts (obj.changes())\n * Will automatically handle key conversion from \"a.b.c\" to \"a -> b -> c\" creation\n\n\n## Simple to use!\n\n```python\n>>> from objict import objict\n>>> d1 = objict(name=\"John\", age=24)\n>>> d1\n{'name': 'John', 'age': 24}\n>>> d1.name\n'John'\n>>> d1.age\n24\n>>> d1.gender = \"male\"\n>>> d1\n{'name': 'John', 'age': 24, 'gender': 'male'}\n>>> d1.gender\n'male'\n>>> import datetime\n>>> d1.dob = datetime.datetime(1985, 5, 2)\n>>> d1.dob\ndatetime.datetime(1985, 5, 2, 0, 0)\n>>> d1.toJSON()\n{'name': 'John', 'age': 24, 'gender': 'male', 'dob': 483865200.0}\n>>> d1.save(\"test1.json\")\n>>> d2 = objict.fromFile(\"test1.json\")\n>>> d2\n{'name': 'John', 'age': 24, 'gender': 'male', 'dob': 483865200.0}\n>>> d2.toXML()\n'<name>John</name><age>24</age><gender>male</gender><dob>483865200.0</dob>'\n>>> d3 = objict(user1=d2)\n>>> d3.user2 = objict(name=\"Jenny\", age=27)\n>>> d3\n{'user1': {'name': 'John', 'age': 24, 'gender': 'male', 'dob': 483865200.0}, 'user2': {'name': 'Jenny', 'age': 27}}\n>>> d3.toXML()\n'<user1><name>John</name><age>24</age><gender>male</gender><dob>483865200.0</dob></user1><user2><name>Jenny</name><age>27</age></user2>'\n>>> d3.toJSON(True)\n'{\\n \"user1\": {\\n \"name\": \"John\",\\n \"age\": 24,\\n \"gender\": \"male\",\\n \"dob\": 483865200.0\\n },\\n \"user2\": {\\n \"name\": \"Jenny\",\\n \"age\": 27\\n }\\n}'\n>>> print(d3.toJSON(True))\n{\n \"user1\": {\n \"name\": \"John\",\n \"age\": 24,\n \"gender\": \"male\",\n \"dob\": 483865200.0\n },\n \"user2\": {\n \"name\": \"Jenny\",\n \"age\": 27\n }\n}\n>>> d3.toZIP()\nb'x\\x9c\\xab\\xe6R\\x00\\x02\\xa5\\xd2\\xe2\\xd4\"C%+\\x85j0\\x17,\\x94\\x97\\x98\\x9b\\n\\x14Q\\xf2\\xca\\xcf\\xc8S\\xd2A\\x88\\'\\xa6\\x83\\x84\\x8dL\\x90\\x84\\xd2S\\xf3RR\\x8b@\\x8as\\x13sR\\x91\\x15\\xa7\\xe4\\'\\x01\\x85M,\\x8c-\\xccL\\x8d\\x0c\\x0c\\xf4\\x0c\\xc0R\\xb5:\\x08[\\x8dp\\xd8\\x9a\\x9a\\x97W\\x89\\xc5Zs\\x88\\x01\\\\\\xb5\\x00^\\x1c\\'I'\n>>> dz = d3.toZIP()\n>>> d4 = objict.fromZIP(dz)\n>>> d4\n{'user1': {'name': 'John', 'age': 24, 'gender': 'male', 'dob': 483865200.0}, 'user2': {'name': 'Jenny', 'age': 27}}\n>>> d5 = d4.copy()\n>>> d5.user1.name\n'John'\n>>> d5.user1.name = \"Jim\"\n>>> d5\n{'user1': {'name': 'Jim', 'age': 24, 'gender': 'male', 'dob': 483865200.0}, 'user2': {'name': 'Jenny', 'age': 27}}\n>>> d5.changes(d4)\n{'user1': {'name': 'John'}}\n\n```\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python dict that supports attribute-style access as well as hierarchical keys, JSON serialization, ZIP compression, and more.",
"version": "1.1.12",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "80e33a493804aa705dde9b044798d4b2f390665eb8e08f073dc4ee1b64cdba0f",
"md5": "a7c3a470ce786802d07b3e6b858dae7e",
"sha256": "9326ab8d4b73392c69de1a94f9d825d91c2bd3f651cac3a8c5a29bf44696d1ed"
},
"downloads": -1,
"filename": "pyobjict-1.1.12-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a7c3a470ce786802d07b3e6b858dae7e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 8086,
"upload_time": "2023-01-11T20:54:06",
"upload_time_iso_8601": "2023-01-11T20:54:06.062296Z",
"url": "https://files.pythonhosted.org/packages/80/e3/3a493804aa705dde9b044798d4b2f390665eb8e08f073dc4ee1b64cdba0f/pyobjict-1.1.12-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "31f039cb06da1ee07688317c5631444a45d5e2b2f25c4443aa1944ec86c4b821",
"md5": "cd007a82abe4acd60a511b35c112160c",
"sha256": "4fa23457455669302502361206b76693fdf249d7be9a52be80c540d23e0f3cc5"
},
"downloads": -1,
"filename": "pyobjict-1.1.12.tar.gz",
"has_sig": false,
"md5_digest": "cd007a82abe4acd60a511b35c112160c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 9008,
"upload_time": "2023-01-11T20:54:07",
"upload_time_iso_8601": "2023-01-11T20:54:07.839625Z",
"url": "https://files.pythonhosted.org/packages/31/f0/39cb06da1ee07688317c5631444a45d5e2b2f25c4443aa1944ec86c4b821/pyobjict-1.1.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-11 20:54:07",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "pyobjict"
}