{ "info": { "author": "Dale Myers", "author_email": "dale@myers.io", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries" ], "description": "# deserialize\n\nA library to make deserialization easy. To get started, just run `pip install deserialize`\n\n### How it used to be\n\nWithout the library, if you want to convert:\n\n```\n{\n \"a\": 1,\n \"b\": 2\n}\n```\n\ninto a dedicated class, you had to do something like this:\n\n```\nclass MyThing:\n\n def __init__(self, a, b):\n self.a = a\n self.b = b\n\n @staticmethod\n def from_json(json_data):\n a_value = json_data.get(\"a\")\n b_value = json_data.get(\"b\")\n\n if a_value is None:\n raise Exception(\"'a' was None\")\n elif b_value is None:\n raise Exception(\"'b' was None\")\n elif type(a_value) != int:\n raise Exception(\"'a' was not an int\")\n elif type(b_value) != int:\n raise Exception(\"'b' was not an int\")\n\n return MyThing(a_value, b_value)\n\nmy_instance = MyThing.from_json(json_data)\n```\n\n### How it is now\n\nWith `deserialize` all you need to do is this:\n\n```\nimport deserialize\n\nclass MyThing:\n a: int\n b: int\n\nmy_instance = deserialize.deserialize(MyThing, json_data)\n```\n\nThat's it. It will pull out all the data and set it for you type checking and even checking for null values.\n\nIf you want null values to be allowed though, that's easy too:\n\n```\nfrom typing import Optional\n\nclass MyThing:\n a: Optional[int]\n b: Optional[int]\n```\n\nNow `None` is a valid value for these.\n\nTypes can be nested as deep as you like. For example, this is perfectly valid:\n\n```\nclass Actor:\n name: str\n age: int\n\nclass Episode:\n title: str\n identifier: st\n actors: List[Actor]\n\nclass Season:\n episodes: List[Episode]\n completed: bool\n\nclass TVShow:\n seasons: List[Season]\n creator: str\n```\n\n## Advanced Usage\n\n### Custom Keys\n\nIt may be that you want to name your properties in your object something different to what is in the data. This can be for readability reasons, or because you have to (such as if your data item is named `__class__`). This can be handled too. Simply use the `key` annotation as follows:\n\n```\n@deserialize.key(\"identifier\", \"id\")\nclass MyClass:\n value: int\n identifier: str\n```\n\nThis will now assign the data with the key `id` to the field `identifier`. You can have multiple annotations to override multiple keys.\n\n### Ignored Keys\n\nYou may want some properties in your object that aren't loaded from disk, but instead created some other way. To do this, use the `ignore` decorator. Here's an example:\n\n```\n@deserialize.ignore(\"identifier\")\nclass MyClass:\n value: int\n identifier: str\n```\n\nWhen deserializing, the library will now ignore the `identifier` property.\n\n### Parsers\n\nSometimes you'll want something in your object in a format that the data isn't in. For example, if you get the data:\n\n```\n{\n \"successful\": True,\n \"timestamp\": 1543770752\n}\n```\n\nYou may want that to be represented as:\n\n```\nclass Result:\n successful: bool\n timestamp: datetime.datetime\n```\n\nBy default, it will fail on this deserialization as the value in the data is not a timestamp. To correct this, use the `parser` decorator to tell it a function to use to parse the data. E.g.\n\n```\n@deserialize.parser(\"timestamp\", datetime.datetime.fromtimestamp)\nclass Result:\n successful: bool\n timestamp: datetime.datetime\n```\n\nThis will now detect when handling the data for the _key_ `timestamp` and run it through the parser function supplied before assigning it to your new class instance.\n\nThe parser is run _before_ type checking is done. This means that if you had something like `Optional[datetime.datetime]`, you should ensure your parser can handle the value being `None`. Your parser will obviously need to return the type that you have declared on the property in order to work.", "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/dalemyers/deserialize", "keywords": "deserialization,deserialize,objects,object,json", "license": "MIT", "maintainer": "Dale Myers", "maintainer_email": "dale@myers.io", "name": "deserialize", "package_url": "https://pypi.org/project/deserialize/", "platform": "", "project_url": "https://pypi.org/project/deserialize/", "project_urls": { "Homepage": "https://github.com/dalemyers/deserialize", "Repository": "https://github.com/dalemyers/deserialize" }, "release_url": "https://pypi.org/project/deserialize/1.0.0/", "requires_dist": null, "requires_python": ">=3.6,<4.0", "summary": "A library to make deserialization easy.", "version": "1.0.0" }, "last_serial": 5939119, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "5b914244ac3b447361134439e83a5439", "sha256": "91c44299282194ebde269663cbc8085e66e9587250b0ce6478b262593ce80356" }, "downloads": -1, "filename": "deserialize-0.1.tar.gz", "has_sig": false, "md5_digest": "5b914244ac3b447361134439e83a5439", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3265, "upload_time": "2018-12-02T13:05:20", "url": "https://files.pythonhosted.org/packages/f8/c4/7ee244f396afbeb3c9231a048b1c87006dec2a513b7d3c56228fb62cd187/deserialize-0.1.tar.gz" } ], "0.10.0": [ { "comment_text": "", "digests": { "md5": "c76efb3602a88f897b3f9a904846f525", "sha256": "0e3f7a2f660aa197966dde2f162bb8ca975d0c6209ec6a3ae865e876412200e8" }, "downloads": -1, "filename": "deserialize-0.10.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c76efb3602a88f897b3f9a904846f525", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 14077, "upload_time": "2019-07-05T10:29:59", "url": "https://files.pythonhosted.org/packages/b7/42/c60db4b64533feef23f2e581dcd94693ee76606e4516b25784afd30ec934/deserialize-0.10.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "00756961daeb48c99a15951883496a5f", "sha256": "e4db7190083a6aafe444889592cd6f2dcc64d354d49791d6c760fd0c34e406da" }, "downloads": -1, "filename": "deserialize-0.10.0.tar.gz", "has_sig": false, "md5_digest": "00756961daeb48c99a15951883496a5f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 6207, "upload_time": "2019-07-05T10:30:00", "url": "https://files.pythonhosted.org/packages/bc/80/c7b7347c624992b7e3f00b589aa5ba733abc6960746d1e3c5038de4d7669/deserialize-0.10.0.tar.gz" } ], "0.11.0": [ { "comment_text": "", "digests": { "md5": "b5ae68e1fa9ff705b9eef8d4a635fa83", "sha256": "8d825130d0fcbd04239161437bc53c23cca4a721278d535bd4ceb5d774c72297" }, "downloads": -1, "filename": "deserialize-0.11.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b5ae68e1fa9ff705b9eef8d4a635fa83", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 7000, "upload_time": "2019-10-07T14:27:52", "url": "https://files.pythonhosted.org/packages/54/17/ec58d2f0bfbcf3c916d0db164bc6ebe74c66b82718cf52c05fd1fd06db6c/deserialize-0.11.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "dcb404f1607281128fadd8667b971e81", "sha256": "97ef1b46c3fc1e8106312f5cfb6aaac6fbed9229c00039241d13212933eb19f1" }, "downloads": -1, "filename": "deserialize-0.11.0.tar.gz", "has_sig": false, "md5_digest": "dcb404f1607281128fadd8667b971e81", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 6411, "upload_time": "2019-10-07T14:27:55", "url": "https://files.pythonhosted.org/packages/eb/53/43ebd33cac61d3a542b94de6a40469143dfaab17425dc55390010706bcbc/deserialize-0.11.0.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "9d7460775fbe9ba3837016b62c088307", "sha256": "4d15d9d4496ea5c75271890fb7ca0f432ef334ca296d481357df4846a37fb525" }, "downloads": -1, "filename": "deserialize-0.2.tar.gz", "has_sig": false, "md5_digest": "9d7460775fbe9ba3837016b62c088307", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4392, "upload_time": "2018-12-02T17:24:40", "url": "https://files.pythonhosted.org/packages/0d/c9/74419db1d484f75c6523b88c017e526e4dc23dd7d266de0d9c3fce54f125/deserialize-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "0e75bf9e8cd6a7bc9fb2ea513762c827", "sha256": "cae0e85ef6f68b32322679ad4f1b62d3e6b8b75020a6ecfcd3187d925feb0a0d" }, "downloads": -1, "filename": "deserialize-0.3.tar.gz", "has_sig": false, "md5_digest": "0e75bf9e8cd6a7bc9fb2ea513762c827", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5405, "upload_time": "2018-12-21T15:38:08", "url": "https://files.pythonhosted.org/packages/04/7c/7e100c530ae0d430440694402bcd93545169ff738177c3d34206263a8e35/deserialize-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "c03b2af3b5ba5daf39b852c7515a1dcf", "sha256": "9ae6143562110b700477b47c976d005a230d43f3fa5f32261311a191b8f0ae2b" }, "downloads": -1, "filename": "deserialize-0.4.tar.gz", "has_sig": false, "md5_digest": "c03b2af3b5ba5daf39b852c7515a1dcf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5443, "upload_time": "2018-12-21T16:15:48", "url": "https://files.pythonhosted.org/packages/bd/fb/4c7c8ef8e5d50d425de9cafecff903706e35df3c111f5ac5f849a7241dd5/deserialize-0.4.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "e6cf63f35488b01804351e23853ec87d", "sha256": "c59e9af7eb86733e516e4742943ae544a4c48088edddcaa103a7fd23cd6251ad" }, "downloads": -1, "filename": "deserialize-0.5.0-py3-none-any.whl", "has_sig": false, "md5_digest": "e6cf63f35488b01804351e23853ec87d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 13942, "upload_time": "2019-01-09T22:16:00", "url": "https://files.pythonhosted.org/packages/c0/31/762c595fd1caf08ac53786fad1596e8ac79bf83f9bf423f2df3cc71fbf3f/deserialize-0.5.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "71ae5c0fe64c807053ab6f39d68e4991", "sha256": "9eb6c05ff810b9003c887239afb18796a172f629932efe0a04d366cfeeb463a2" }, "downloads": -1, "filename": "deserialize-0.5.0.tar.gz", "has_sig": false, "md5_digest": "71ae5c0fe64c807053ab6f39d68e4991", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 6000, "upload_time": "2019-01-09T22:16:02", "url": "https://files.pythonhosted.org/packages/f3/5a/76334545014a17c026b354e9abe15549e40d86f8a200048cf8c0ff9fcca9/deserialize-0.5.0.tar.gz" } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "55a80c8b5d4cdc384d7d9f9509777250", "sha256": "b81c6fd13b18e897b26a07f4fb8bbf57fbafb98dae553e9baa26f7bdaa345da9" }, "downloads": -1, "filename": "deserialize-0.6.0-py3-none-any.whl", "has_sig": false, "md5_digest": "55a80c8b5d4cdc384d7d9f9509777250", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 14007, "upload_time": "2019-02-10T16:32:37", "url": "https://files.pythonhosted.org/packages/9e/db/77cf53f1693ea763fb667f5957870d2742063d0801b1f0f8b9bde38eb971/deserialize-0.6.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2f3ed724d180d648bb687a18f91d1354", "sha256": "fc743bd64de06268584ca5190998763a943612c741855cf5f3acf1ec16835502" }, "downloads": -1, "filename": "deserialize-0.6.0.tar.gz", "has_sig": false, "md5_digest": "2f3ed724d180d648bb687a18f91d1354", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 6143, "upload_time": "2019-02-10T16:32:38", "url": "https://files.pythonhosted.org/packages/83/61/f059b79757fc5c61af9eb5248d907eb96ad87ecc3c98504f3a62d07410eb/deserialize-0.6.0.tar.gz" } ], "0.7.0": [ { "comment_text": "", "digests": { "md5": "c5c5abe8110a04f9cebf8e97996b1612", "sha256": "74d4fff3076b6c7e5772229be157448496ce487d43f092ef25d42fcbf02ba67d" }, "downloads": -1, "filename": "deserialize-0.7.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c5c5abe8110a04f9cebf8e97996b1612", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 14957, "upload_time": "2019-02-10T16:53:14", "url": "https://files.pythonhosted.org/packages/0c/e7/b689ca6daa40b05295299299c982477ee3ab7d79160cf6abfe57f1305bd0/deserialize-0.7.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b7ff12bd21ef7356c94fbbd3d6340560", "sha256": "c05833415196334e82644c9199a7ba861b9ae31371bdd41d51673940a7136ab3" }, "downloads": -1, "filename": "deserialize-0.7.0.tar.gz", "has_sig": false, "md5_digest": "b7ff12bd21ef7356c94fbbd3d6340560", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 6365, "upload_time": "2019-02-10T16:53:16", "url": "https://files.pythonhosted.org/packages/10/d4/37b0e5bf2bb62047fc4f091d6d54236c714affeda58fb26e4fffc2d3bd1a/deserialize-0.7.0.tar.gz" } ], "0.8.0": [ { "comment_text": "", "digests": { "md5": "1b7f0fa85d0270dd9bce8c0558bbfac1", "sha256": "100f5958ef0405879d54526b6cd0b6c69f86b0be98e462895c05a26a30660ed8" }, "downloads": -1, "filename": "deserialize-0.8.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1b7f0fa85d0270dd9bce8c0558bbfac1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 15313, "upload_time": "2019-03-22T09:44:20", "url": "https://files.pythonhosted.org/packages/7f/2d/8616e88ad27a07831098681f313551a724fac6e7d07d472a0469cd9ff71f/deserialize-0.8.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6436f7b514602f17ce9e4c43e55f25b4", "sha256": "cc4cbd29ab591ebc419d5166701a2fc3e6bd4478a78252c2cb99284731c071e2" }, "downloads": -1, "filename": "deserialize-0.8.0.tar.gz", "has_sig": false, "md5_digest": "6436f7b514602f17ce9e4c43e55f25b4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 6461, "upload_time": "2019-03-22T09:44:22", "url": "https://files.pythonhosted.org/packages/18/4d/0d07b196994e53cdc57744ef19e8bbf4f0e30c22afa0536775465ba7d642/deserialize-0.8.0.tar.gz" } ], "0.9.0": [ { "comment_text": "", "digests": { "md5": "1e7ddfd03e971e4bcb1bb67628a43b4d", "sha256": "fb66fead084263b5832d7668e20035d908190a71e8c35b818c7653bd5b4590d1" }, "downloads": -1, "filename": "deserialize-0.9.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1e7ddfd03e971e4bcb1bb67628a43b4d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 16502, "upload_time": "2019-05-16T12:22:26", "url": "https://files.pythonhosted.org/packages/f7/bd/7eaf782f02be99dc70ea4019810f62d9728b356e9d498a6ea9e27edeb7c6/deserialize-0.9.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3fa23418aa7468e5087015a99fb73b2b", "sha256": "3371ca974970fc543a2d0e0b95383d7221bf0ac05066e594ad9bb06e1c5ef883" }, "downloads": -1, "filename": "deserialize-0.9.0.tar.gz", "has_sig": false, "md5_digest": "3fa23418aa7468e5087015a99fb73b2b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 6806, "upload_time": "2019-05-16T12:22:27", "url": "https://files.pythonhosted.org/packages/f9/8c/7539f5b9861b25da49ec345cb00019e796c5a366ca2f80b69becb756a6f9/deserialize-0.9.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "529191cc1ec22e5090525e55f9494426", "sha256": "61d1b2d8fcfab0ba06a8decf1d3b6e0798dddb5268b980ca56a8cd3edfe5e26b" }, "downloads": -1, "filename": "deserialize-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "529191cc1ec22e5090525e55f9494426", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 6989, "upload_time": "2019-10-07T14:35:39", "url": "https://files.pythonhosted.org/packages/3f/a9/968765f7abb2fdda6e59c34b3d32780d0a5c6021d709f46beea126d0eada/deserialize-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6c432772722370c13022b3b2e9df4846", "sha256": "2fd568f5be2c839ed27316d6c6640674cd5af28b24f0a0951466c7cc8eb99af1" }, "downloads": -1, "filename": "deserialize-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6c432772722370c13022b3b2e9df4846", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 6416, "upload_time": "2019-10-07T14:35:41", "url": "https://files.pythonhosted.org/packages/20/9d/371ab764670f324c1ee527f7ccaf0d35649b6a5139259f0367b7572775a0/deserialize-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "529191cc1ec22e5090525e55f9494426", "sha256": "61d1b2d8fcfab0ba06a8decf1d3b6e0798dddb5268b980ca56a8cd3edfe5e26b" }, "downloads": -1, "filename": "deserialize-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "529191cc1ec22e5090525e55f9494426", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 6989, "upload_time": "2019-10-07T14:35:39", "url": "https://files.pythonhosted.org/packages/3f/a9/968765f7abb2fdda6e59c34b3d32780d0a5c6021d709f46beea126d0eada/deserialize-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6c432772722370c13022b3b2e9df4846", "sha256": "2fd568f5be2c839ed27316d6c6640674cd5af28b24f0a0951466c7cc8eb99af1" }, "downloads": -1, "filename": "deserialize-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6c432772722370c13022b3b2e9df4846", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 6416, "upload_time": "2019-10-07T14:35:41", "url": "https://files.pythonhosted.org/packages/20/9d/371ab764670f324c1ee527f7ccaf0d35649b6a5139259f0367b7572775a0/deserialize-1.0.0.tar.gz" } ] }