{ "info": { "author": "Rolf van Kleef", "author_email": "pypi@rolfvankleef.nl", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Utilities" ], "description": "# Dictionary deserializer\n[![ReadTheDocs](https://readthedocs.org/projects/dict-deserializer/badge/?version=latest&style=flat)](https://dict-deserializer.rtfd.io)\n[![GitHub issues](https://img.shields.io/github/issues/rhbvkleef/dict_deserializer.svg)](https://github.com/rhbvkleef/dict_deserializer)\n[![GitHub pull requests](https://img.shields.io/github/issues-pr/rhbvkleef/dict_deserializer.svg)](https://github.com/rhbvkleef/dict_deserializer)\n[![PyPI](https://img.shields.io/pypi/v/dictionary-deserializer.svg)](https://pypi.org/project/Dictionary-deserializer/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/dictionary-deserializer.svg)](https://pypi.org/project/Dictionary-deserializer/)\n[![GitHub](https://img.shields.io/github/license/rhbvkleef/dict_deserializer.svg)](https://opensource.org/licenses/BSD-3-Clause)\n\nDictionary deserializer is a project built to convert dictionaries into\ncomposite classes in an intuitive way. Special attention was also paid\nto being friendly to static type-checkers and IDE autocompletes.\n\nIt is expected that this library is used together with a JSON-to-dict\ndeserializer like `json.loads`.\n\n## Installation\n\nIn order to use it, simply add the dependency `dictionary-deserializer` to your\nrequirements file:\n\n### Pipenv\n\n```bash\npipenv install dictionary-deserializer\n```\n\n### Pip\n\n```bash\npip install dictionary-deserializer\npip freeze > requirements.txt\n```\n\n## Design\n\nThis project was originally meant as a proof of concept, to be used to find\nother projects that would be able to replace this, with the required feature\nset. That project was not found, and therefore, this project was expanded.\n\n### Requirements\n\n* Use type hints for type validation\n* Allow polymorphism\n * Through `typing.Union`s\n * Through subclassing\n* Support a large part of the `typing` module's types\n* Allow validations on values\n* Be able to validate and deserialize _any_ compliant JSON structure\n* Be compatible with static type checkers and IDE hinting\n* Have a small impact on existing code starting to use this library\n\n## Examples\n\nNone of this code is actually useful if you don't understand how to use it. It\nis very simple. Here are some examples:\n\n### Specifying a structure\n\n```python\nfrom typing import Optional\n\nfrom dict_deserializer.deserializer import Deserializable\n\nclass User(Deserializable):\n email: str # Type must be a string\n username: str # Type must be a string\n password: Optional[str] # Type must either be a string or a None\n```\n\n### Deserialization\n\n```python\nfrom dict_deserializer.deserializer import deserialize, Rule\n\n# Successful\ndeserialize(Rule(User), {\n 'email': 'pypi@rolfvankleef.nl',\n 'username': 'rkleef',\n})\n\n# Fails because optional type is wrong\ndeserialize(Rule(User), {\n 'email': 'pypi@rolfvankleef.nl',\n 'username': 'rkleef',\n 'password': 9.78,\n})\n```\n\n### Polymorphic structures\n```python\nfrom typing import Optional, Any, List\n\nfrom dict_deserializer.deserializer import Deserializable\nfrom dict_deserializer.annotations import abstract\n\n@abstract\nclass DirectoryObject(Deserializable):\n name: str\n meta: Any\n\nclass User(DirectoryObject):\n full_name: str\n first_name: Optional[str]\n\nclass Group(DirectoryObject):\n members: List[DirectoryObject]\n```\n\nIf you deserialize into `Rule(DirectoryObject)`, the matching class will\nautomatically be selected. If none of the subclasses match, an error is thrown\nsince the DirectoryObject is declared abstract.\n\nIf you want to discriminate not by field names or types, but by their values,\none can choose to define a `@discriminator` annotation.\n\n### Value validations\n\nThe syntax for validating the value of a key is currently a bit weird. It is\nincompatible with existing syntax for defaults, but the type syntax is the same.\n\nExample:\n\n```python\nfrom typing import Optional\n\nfrom dict_deserializer.deserializer import Deserializable\nfrom dict_deserializer.annotations import validated\n\nclass Test(Deserializable):\n name: Optional[str]\n\n @validated(default='Unknown')\n def name(self, value):\n if len(value) > 20:\n raise TypeError('Name may not be longer than 20 characters.')\n\n```\n\n## Limitations\n\nThis library uses the `typing` module extensively. It does, however, only\nsupport some of its types. This is a list of verified composite types:\n\n* `Union` (Including `Optional`)\n* `Dict`\n* `List`\n* `Tuple`\n* `Any`\n* `dict_deserializer.deserializer.Deserializable`\n* `dict`\n* `list`\n\nIt supports these types as terminal types:\n\n* `int`\n* `float`\n* `str`\n* `NoneType`\n* `bool`\n\n## Planned features\n\n* NamedTuples\n * The anonymous namedtuple and the class-namedtuples with (optionally) type annotations.\n* Dataclasses\n* A way to allow deserializing into a class not extending `Deserializable`\n* Enums\n* Sets\n * From lists\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/rhbvkleef/dict_deserializer", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "Dictionary-deserializer", "package_url": "https://pypi.org/project/Dictionary-deserializer/", "platform": "", "project_url": "https://pypi.org/project/Dictionary-deserializer/", "project_urls": { "Homepage": "https://github.com/rhbvkleef/dict_deserializer" }, "release_url": "https://pypi.org/project/Dictionary-deserializer/0.0.6/", "requires_dist": [ "typeguard" ], "requires_python": "", "summary": "Dictionary deserializer is a package that aides in the deserializing of JSON (or other structures) that are converted to dicts, into composite classes.", "version": "0.0.6" }, "last_serial": 4866684, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "4946538b9d7e6e0f5acf34842ec58f09", "sha256": "64fc37c9562adb56761f4b7f34a8344985528d4ebafe7fae466c2b01992eb774" }, "downloads": -1, "filename": "Dictionary_deserializer-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "4946538b9d7e6e0f5acf34842ec58f09", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13876, "upload_time": "2018-11-01T18:59:34", "url": "https://files.pythonhosted.org/packages/f8/e7/a9772756f308f914a1bbc265c92d2b42f2f932202d9555cf082cf8412e87/Dictionary_deserializer-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3748053832a39592c544526fff5d1856", "sha256": "605ae92dd7ecdb43c6899ca258fd111589b05e0bd32643a69d9b277f54e5ea79" }, "downloads": -1, "filename": "Dictionary deserializer-0.0.1.tar.gz", "has_sig": false, "md5_digest": "3748053832a39592c544526fff5d1856", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3372, "upload_time": "2018-11-01T18:59:36", "url": "https://files.pythonhosted.org/packages/f9/2f/6d60bb26b93c0b2c6b3a9632b9074740f32ba97e387753d66fe6c72f6f18/Dictionary%20deserializer-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "3d2792121381882df0efc05188695204", "sha256": "b9662ae48c734ccf9262b5db255a9ea1640c09f0a50e5d0f8939316f37490530" }, "downloads": -1, "filename": "Dictionary_deserializer-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "3d2792121381882df0efc05188695204", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13893, "upload_time": "2018-11-01T19:08:52", "url": "https://files.pythonhosted.org/packages/02/bc/b40e2c5f60ca5916554d0fdd8aeb3061c45792730a676d6887cad29cc92b/Dictionary_deserializer-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "57335ecce486b1051d272691360806dd", "sha256": "87f8d97f9274048473f8bf6a2b0e74429036b831a788867702e3c40802b36647" }, "downloads": -1, "filename": "Dictionary deserializer-0.0.2.tar.gz", "has_sig": false, "md5_digest": "57335ecce486b1051d272691360806dd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3419, "upload_time": "2018-11-01T19:08:54", "url": "https://files.pythonhosted.org/packages/1f/88/f735123782baa2f3343206777e9089aa01b487b52d57401ac2bcc2efba17/Dictionary%20deserializer-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "17df46bd71521e4c8947735e715bd3e9", "sha256": "8ee8e15592c4cdc2b6417223b6b5faf622577b7a256fb4a34bb30d9df888ad78" }, "downloads": -1, "filename": "Dictionary_deserializer-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "17df46bd71521e4c8947735e715bd3e9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14765, "upload_time": "2018-11-08T20:33:37", "url": "https://files.pythonhosted.org/packages/d5/6b/af2f0b502854ef6f62e2b569874c2aff6d26e21f6a7a40126cd8939e881b/Dictionary_deserializer-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4e88c1a374d2a938ad26c8e926b9b4d8", "sha256": "c1ee4a0ff096cd879873f543793abd04034a5033173119360200c5fc2c992570" }, "downloads": -1, "filename": "Dictionary deserializer-0.0.3.tar.gz", "has_sig": false, "md5_digest": "4e88c1a374d2a938ad26c8e926b9b4d8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4351, "upload_time": "2018-11-08T20:33:39", "url": "https://files.pythonhosted.org/packages/c1/8c/e2b1f07303f3bdc21b644224d89f5667bf38e557c3c597aabf30890d4aa8/Dictionary%20deserializer-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "24a22f9df2c1dfc887b8ca5fd15d3096", "sha256": "bbae72ddf8f58c5ffff09e1ce01427f9c7d99c6a24ffbce40d6be9751c84fa35" }, "downloads": -1, "filename": "Dictionary_deserializer-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "24a22f9df2c1dfc887b8ca5fd15d3096", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 16790, "upload_time": "2018-11-12T12:00:20", "url": "https://files.pythonhosted.org/packages/1f/20/5e566f9e13c7eabdf271fd40c7b1b812476b9d80eda126d5a207383dfdb3/Dictionary_deserializer-0.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0d4e616832c8e929ff615e71118507b6", "sha256": "e2405149ab63aac06ee510f208c5220414153b74b90699f3e1ea675f7a00a78b" }, "downloads": -1, "filename": "Dictionary deserializer-0.0.4.tar.gz", "has_sig": false, "md5_digest": "0d4e616832c8e929ff615e71118507b6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6534, "upload_time": "2018-11-12T12:00:22", "url": "https://files.pythonhosted.org/packages/1a/6d/a1ad806f7207465da168eb7406f51b04f84c2e027abb7090a486d4eb8f78/Dictionary%20deserializer-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "9905e0442d12810ba3fbc298ccd2b948", "sha256": "22f1d40da668f55bdce63c475984783b69339b5097907a385c59a6fa80eb74ea" }, "downloads": -1, "filename": "Dictionary_deserializer-0.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "9905e0442d12810ba3fbc298ccd2b948", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17028, "upload_time": "2019-01-31T21:10:16", "url": "https://files.pythonhosted.org/packages/32/80/14c14aaaf028016c99addcf343e951ce6694eacb2e37898fa06442c8f81f/Dictionary_deserializer-0.0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "11eb26d7ebddf54c65d699a0e88d6369", "sha256": "41f93cc2211661a2028364e76d117fd1b0f32e823ff4cb7822065bd99609c8ef" }, "downloads": -1, "filename": "Dictionary deserializer-0.0.5.tar.gz", "has_sig": false, "md5_digest": "11eb26d7ebddf54c65d699a0e88d6369", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6754, "upload_time": "2019-01-31T21:10:17", "url": "https://files.pythonhosted.org/packages/0d/54/bcaf1e18adb5ee448cecf68f386e5d979f48e43aff297afa08336e58f0f6/Dictionary%20deserializer-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "7873cc1b3258d1b1e8187b81b4e7d66f", "sha256": "cbed3e316912ed72a05afeda5e24aa7195c9e073eb473e9f4eca94020a3f1c99" }, "downloads": -1, "filename": "Dictionary_deserializer-0.0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "7873cc1b3258d1b1e8187b81b4e7d66f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9069, "upload_time": "2019-02-25T21:02:07", "url": "https://files.pythonhosted.org/packages/9b/0f/1b0f7146e66bba176a5ece5877d1518f2f2df8669c95ec11b14c9f2cc3b3/Dictionary_deserializer-0.0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1d7f36b5516278e588e9d46846dd7e3d", "sha256": "749bba068d7f677a225e8a11646e4c24cfabfc3096f98e43aa9417483fa15314" }, "downloads": -1, "filename": "Dictionary deserializer-0.0.6.tar.gz", "has_sig": false, "md5_digest": "1d7f36b5516278e588e9d46846dd7e3d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7492, "upload_time": "2019-02-25T21:02:09", "url": "https://files.pythonhosted.org/packages/d6/5a/fbeacc0fe0888dc9a5654689b7c7c85139274c509baf7dd110b6a6e0e24f/Dictionary%20deserializer-0.0.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7873cc1b3258d1b1e8187b81b4e7d66f", "sha256": "cbed3e316912ed72a05afeda5e24aa7195c9e073eb473e9f4eca94020a3f1c99" }, "downloads": -1, "filename": "Dictionary_deserializer-0.0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "7873cc1b3258d1b1e8187b81b4e7d66f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9069, "upload_time": "2019-02-25T21:02:07", "url": "https://files.pythonhosted.org/packages/9b/0f/1b0f7146e66bba176a5ece5877d1518f2f2df8669c95ec11b14c9f2cc3b3/Dictionary_deserializer-0.0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1d7f36b5516278e588e9d46846dd7e3d", "sha256": "749bba068d7f677a225e8a11646e4c24cfabfc3096f98e43aa9417483fa15314" }, "downloads": -1, "filename": "Dictionary deserializer-0.0.6.tar.gz", "has_sig": false, "md5_digest": "1d7f36b5516278e588e9d46846dd7e3d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7492, "upload_time": "2019-02-25T21:02:09", "url": "https://files.pythonhosted.org/packages/d6/5a/fbeacc0fe0888dc9a5654689b7c7c85139274c509baf7dd110b6a6e0e24f/Dictionary%20deserializer-0.0.6.tar.gz" } ] }