{ "info": { "author": "Matt Bachmann", "author_email": "bachmann.matt@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "=====================\nMarshmallow-Polyfield\n=====================\n\n.. image:: https://readthedocs.org/projects/marshmallow-polyfield/badge/?version=latest\n :target: https://readthedocs.org/projects/marshmallow-polyfield/?badge=latest\n :alt: Documentation Status\n.. image:: https://travis-ci.org/Bachmann1234/marshmallow-polyfield.svg?branch=master\n :target: https://travis-ci.org/Bachmann1234/marshmallow-polyfield\n :alt: Build Status\n.. image:: https://coveralls.io/repos/Bachmann1234/marshmallow-polyfield/badge.svg?branch=master&service=github\n :target: https://coveralls.io/github/Bachmann1234/marshmallow-polyfield?branch=master\n :alt: Coverage Status\n\nThis branch supports Marshmallow 3.0 and above. For 2.0 support see `The 2.0 branch `_ \n\nAn unofficial extension to Marshmallow to allow for polymorphic fields.\n\nMarshmallow is a fantastic library for serialization and deserialization of data.\nFor more on that project see its `GitHub `_ page or its `Documentation `_.\n\nThis project adds a custom field designed for polymorphic types. This allows you to define a schema that says \"This field accepts anything of type X\"\n\nThe secret to this field is that you need to define two functions. One to be used when serializing, and another for deserializing. These functions\ntake in the raw value and return the schema to use.\n\nThis field should support the same properties as other Marshmallow fields. I have worked with *required* *allow_none* and *many*.\n\nLast version support v2 is tagged FINAL_V2_VERSION\n\nInstalling\n----------\n::\n\n $ pip install marshmallow-polyfield\n\nImporting\n---------\nHere is how to import the necessary field class\n::\n\n from marshmallow_polyfield import PolyField\n\nExample\n-------\n\nThe code below demonstrates how to setup a schema with a PolyField. For the full context check out the tests.\nOnce setup the schema should act like any other schema. If it does not then please file an Issue.\n\n.. code:: python\n\n def shape_schema_serialization_disambiguation(base_object, parent_obj):\n class_to_schema = {\n Rectangle.__name__: RectangleSchema,\n Triangle.__name__: TriangleSchema\n }\n try:\n return class_to_schema[base_object.__class__.__name__]()\n except KeyError:\n pass\n\n raise TypeError(\"Could not detect type. \"\n \"Did not have a base or a length. \"\n \"Are you sure this is a shape?\")\n\n\n def shape_schema_deserialization_disambiguation(object_dict, parent_object_dict):\n if object_dict.get(\"base\"):\n return TriangleSchema()\n elif object_dict.get(\"length\"):\n return RectangleSchema()\n\n raise TypeError(\"Could not detect type. \"\n \"Did not have a base or a length. \"\n \"Are you sure this is a shape?\")\n\n\n class ContrivedShapeClass(object):\n def __init__(self, main, others):\n self.main = main\n self.others = others\n\n def __eq__(self, other):\n return self.__dict__ == other.__dict__\n\n\n class ContrivedShapeClassSchema(Schema):\n main = PolyField(\n serialization_schema_selector=shape_schema_serialization_disambiguation,\n deserialization_schema_selector=shape_schema_deserialization_disambiguation,\n required=True\n )\n others = PolyField(\n serialization_schema_selector=shape_schema_serialization_disambiguation,\n deserialization_schema_selector=shape_schema_deserialization_disambiguation,\n allow_none=True,\n many=True\n )\n\n @post_load\n def make_object(self, data):\n return TestPolyField.ContrivedShapeClass(\n data.get('main'),\n data.get('others')\n )", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Bachmann1234/marshmallow-polyfield", "keywords": "serialization,rest,json,api,marshal,marshalling,deserialization,validation,schema", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "marshmallow-polyfield", "package_url": "https://pypi.org/project/marshmallow-polyfield/", "platform": "", "project_url": "https://pypi.org/project/marshmallow-polyfield/", "project_urls": { "Homepage": "https://github.com/Bachmann1234/marshmallow-polyfield" }, "release_url": "https://pypi.org/project/marshmallow-polyfield/5.7/", "requires_dist": null, "requires_python": "", "summary": "An unofficial extension to Marshmallow to allow for polymorphic fields", "version": "5.7" }, "last_serial": 5494959, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "c6d25bde88c1e9d80c3d264a2f783789", "sha256": "b6402786f30dbe6c84471b57d655ee932742c0bf9f943280592183638a0ba5a4" }, "downloads": -1, "filename": "marshmallow-polyfield-1.0.tar.gz", "has_sig": true, "md5_digest": "c6d25bde88c1e9d80c3d264a2f783789", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8755, "upload_time": "2015-09-08T00:42:23", "url": "https://files.pythonhosted.org/packages/04/0a/4934f154ee829a34bb221d79b26c65356f2fbaa752a2503cca4f26caecef/marshmallow-polyfield-1.0.tar.gz" } ], "2.0": [ { "comment_text": "", "digests": { "md5": "de6c975f65ec3de2cf35c31f83dc9cfa", "sha256": "9e838e30ecc06ecdada728ff8734cfa3c947f2b9781d32357c574664572374b6" }, "downloads": -1, "filename": "marshmallow-polyfield-2.0.tar.gz", "has_sig": true, "md5_digest": "de6c975f65ec3de2cf35c31f83dc9cfa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8854, "upload_time": "2015-09-08T14:31:50", "url": "https://files.pythonhosted.org/packages/b5/ac/46e223d4ac1f7452a4ad25cea0650db147b183ada7fd56b9e8df374c3f72/marshmallow-polyfield-2.0.tar.gz" } ], "2.1": [ { "comment_text": "", "digests": { "md5": "0ee147801bdbe80cc936d18e069826ac", "sha256": "ce8b6d9f4a9a0ae2f45da277812ed27fcde7eb725234266b16d51351aedddfd9" }, "downloads": -1, "filename": "marshmallow-polyfield-2.1.tar.gz", "has_sig": true, "md5_digest": "0ee147801bdbe80cc936d18e069826ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8889, "upload_time": "2015-09-08T15:02:29", "url": "https://files.pythonhosted.org/packages/e8/57/0358ecf2178b50d9a5e69812d201e041137414294612f2be2989f4d1a725/marshmallow-polyfield-2.1.tar.gz" } ], "2.2": [ { "comment_text": "", "digests": { "md5": "3c4723cd319dee67712cb9596df78d23", "sha256": "a53ccbdaeea39ec8942362074b0f5950892654ed2bde82a27e69f63d820c419b" }, "downloads": -1, "filename": "marshmallow-polyfield-2.2.tar.gz", "has_sig": true, "md5_digest": "3c4723cd319dee67712cb9596df78d23", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8942, "upload_time": "2015-09-08T23:16:12", "url": "https://files.pythonhosted.org/packages/95/d6/5961e98ba92b527bfa05c8c7e4a82cb4ff41aac5c42ed358f62e122d21bc/marshmallow-polyfield-2.2.tar.gz" } ], "2.3": [ { "comment_text": "", "digests": { "md5": "7119d3471703a86c8b72696e5472b8e8", "sha256": "f4ac2a8276c4ed358622da99a18d3facc467ff0ee2c7ddcae1d420476a7e9cef" }, "downloads": -1, "filename": "marshmallow-polyfield-2.3.tar.gz", "has_sig": true, "md5_digest": "7119d3471703a86c8b72696e5472b8e8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9126, "upload_time": "2015-09-08T23:29:06", "url": "https://files.pythonhosted.org/packages/dd/23/d51916f463771f7dc387d97def934d61710a841a02cce9656ba0e00ef6a7/marshmallow-polyfield-2.3.tar.gz" } ], "2.4": [ { "comment_text": "", "digests": { "md5": "70c3178c0d00a1c92ff98edfc41de14f", "sha256": "f23f2101e47aebf947d1a95d1a520c3ae1121bf0700464aae1d1ff689bedc2a3" }, "downloads": -1, "filename": "marshmallow-polyfield-2.4.tar.gz", "has_sig": true, "md5_digest": "70c3178c0d00a1c92ff98edfc41de14f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9127, "upload_time": "2015-09-08T23:37:41", "url": "https://files.pythonhosted.org/packages/2f/e7/0ca95f6e69980899ccac00da06db27646d5f8548c1d96e54b3dacafdb30e/marshmallow-polyfield-2.4.tar.gz" } ], "2.5": [ { "comment_text": "", "digests": { "md5": "e93789ea71145f423cb5bcc7e4a271c3", "sha256": "caf0035ee12e36452944bc3d171675126b77a69e20f291963848ba2d7f9b6df0" }, "downloads": -1, "filename": "marshmallow-polyfield-2.5.tar.gz", "has_sig": false, "md5_digest": "e93789ea71145f423cb5bcc7e4a271c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9149, "upload_time": "2015-09-14T03:25:09", "url": "https://files.pythonhosted.org/packages/95/eb/f42fe67c17190d669133132704a748d6f5a03f184d70004e8f4282ac47cb/marshmallow-polyfield-2.5.tar.gz" } ], "2.6": [ { "comment_text": "", "digests": { "md5": "7327425b87f8d90215eca33f40fcce4f", "sha256": "b5be8d85f109ea5c4506c45efd7cf2af4a3424bf874ff86dd1c56d4cfdf501fc" }, "downloads": -1, "filename": "marshmallow-polyfield-2.6.tar.gz", "has_sig": true, "md5_digest": "7327425b87f8d90215eca33f40fcce4f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9308, "upload_time": "2015-09-17T03:22:01", "url": "https://files.pythonhosted.org/packages/60/58/7895a83bb63f1f20172b2a7af74816d8287b881588233b4aba5fe62bc278/marshmallow-polyfield-2.6.tar.gz" } ], "2.7": [ { "comment_text": "", "digests": { "md5": "f0dc2e0e0c6ec760cf21beba0b1acbd9", "sha256": "08bca0f58be1fe0fa35f955429caabda336cee4aceec9235de779521eebb18a8" }, "downloads": -1, "filename": "marshmallow-polyfield-2.7.tar.gz", "has_sig": true, "md5_digest": "f0dc2e0e0c6ec760cf21beba0b1acbd9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9278, "upload_time": "2015-11-02T05:13:44", "url": "https://files.pythonhosted.org/packages/f3/a5/b0563df7612b40b3ef7c2f025ff7cd3019c904d33120a68f5e6f1c12c160/marshmallow-polyfield-2.7.tar.gz" } ], "3.0": [ { "comment_text": "", "digests": { "md5": "5f87784d3fe8854ca58cf34324431b89", "sha256": "2a5e302b522105994f7d75c475467e8286a01789f404b33dd7dfebb66a5a5f5c" }, "downloads": -1, "filename": "marshmallow-polyfield-3.0.tar.gz", "has_sig": true, "md5_digest": "5f87784d3fe8854ca58cf34324431b89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9602, "upload_time": "2015-12-22T04:12:53", "url": "https://files.pythonhosted.org/packages/0b/06/01fe98f935a9bf61429618045d76cb08271f2b25ddacb71e0cb1ad722cc4/marshmallow-polyfield-3.0.tar.gz" } ], "3.1": [ { "comment_text": "", "digests": { "md5": "1d1860f98b8b24e72d45e8f7f2b9a35a", "sha256": "cae51ace94d81eb35ae6f1a0491ec1a881f111c4a10a0df74d0282ac68bd429f" }, "downloads": -1, "filename": "marshmallow-polyfield-3.1.tar.gz", "has_sig": true, "md5_digest": "1d1860f98b8b24e72d45e8f7f2b9a35a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9617, "upload_time": "2016-07-14T02:53:29", "url": "https://files.pythonhosted.org/packages/ee/80/c3d205f7cd4edb5e630711ee05cdf9a94934f884fd15f9595521ca8f842e/marshmallow-polyfield-3.1.tar.gz" } ], "3.2": [ { "comment_text": "", "digests": { "md5": "7f062ec7b92bef6563b122ca90362b5c", "sha256": "cc57436b6fb65f33912c8f110d710933aa5a3082409cd5f9f0d8df6ec24d4280" }, "downloads": -1, "filename": "marshmallow_polyfield-3.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7f062ec7b92bef6563b122ca90362b5c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 17083, "upload_time": "2017-10-09T23:53:53", "url": "https://files.pythonhosted.org/packages/fa/ba/6406b8cce3e42b2838d234310c3605627083bbb8f71dcc312c616480fe92/marshmallow_polyfield-3.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b89f0ba7a85f1bc0856e9709fe929ca2", "sha256": "8d85301eb0f46ec184bac534a78472966f9cc3cbfab7fae58ddf8c0a954081cd" }, "downloads": -1, "filename": "marshmallow_polyfield-3.2-py3-none-any.whl", "has_sig": false, "md5_digest": "b89f0ba7a85f1bc0856e9709fe929ca2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17060, "upload_time": "2017-09-25T00:47:10", "url": "https://files.pythonhosted.org/packages/6e/0d/744a3e7738123bcac0498c6137865f2edb64aeea59ef3792f440156d3132/marshmallow_polyfield-3.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d5bffad89c9ff26931316b0307661f81", "sha256": "72980cb9a43a7c750580b4b08e9d01a8cbd583e1f59360f1924a1ed60f065a4c" }, "downloads": -1, "filename": "marshmallow-polyfield-3.2.tar.gz", "has_sig": false, "md5_digest": "d5bffad89c9ff26931316b0307661f81", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9632, "upload_time": "2017-10-09T23:53:55", "url": "https://files.pythonhosted.org/packages/4c/75/a7cb737e27265eac47c854b01beb8abed1648a87c82f68c85b105102aeb5/marshmallow-polyfield-3.2.tar.gz" } ], "4.2": [ { "comment_text": "", "digests": { "md5": "3a18f0323992b8de808747c5531d66a9", "sha256": "20a80bf2e81f7a42f0bdab32610dc6a890d44b18b123d4b084a41b1476537662" }, "downloads": -1, "filename": "marshmallow-polyfield-4.2.tar.gz", "has_sig": false, "md5_digest": "3a18f0323992b8de808747c5531d66a9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11004, "upload_time": "2018-12-18T04:00:16", "url": "https://files.pythonhosted.org/packages/59/fd/5997a5ab34fb8e8d98d84f470f675ca668c076a9618cf9ba4581cbe131ea/marshmallow-polyfield-4.2.tar.gz" } ], "5.0": [ { "comment_text": "", "digests": { "md5": "3387d4ec31210b16373abdc1787652aa", "sha256": "4540c869a01f70893498a6adfdbec86859d3661459174faba28da46a767ca8d3" }, "downloads": -1, "filename": "marshmallow-polyfield-5.0.tar.gz", "has_sig": false, "md5_digest": "3387d4ec31210b16373abdc1787652aa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10924, "upload_time": "2018-12-14T02:57:16", "url": "https://files.pythonhosted.org/packages/d2/3a/6aa15200bf0fe5fd8d66a5a97c182c78412f726b0cd26191bce6474b87e2/marshmallow-polyfield-5.0.tar.gz" } ], "5.1": [ { "comment_text": "", "digests": { "md5": "16474b7625244181261ccf54184d7520", "sha256": "3cb973b3fa1f1fd64002fdefa32608a3399acd4ae400a692380fa18c6db2a055" }, "downloads": -1, "filename": "marshmallow-polyfield-5.1.tar.gz", "has_sig": false, "md5_digest": "16474b7625244181261ccf54184d7520", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10934, "upload_time": "2018-12-15T16:02:45", "url": "https://files.pythonhosted.org/packages/53/83/9b726305319ca65f8bb516f04cc65f2b03ab652264c1802cdc48012e7fba/marshmallow-polyfield-5.1.tar.gz" } ], "5.2": [ { "comment_text": "", "digests": { "md5": "d4e1ff9eb1076700ea3c9d5259d5317f", "sha256": "1fbe84984d51206ca790a3bbac92da3b692e9ccc347bdaf2e17c0cdf522dbdd9" }, "downloads": -1, "filename": "marshmallow-polyfield-5.2.tar.gz", "has_sig": false, "md5_digest": "d4e1ff9eb1076700ea3c9d5259d5317f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11282, "upload_time": "2018-12-16T00:07:35", "url": "https://files.pythonhosted.org/packages/ca/cc/f5098f0edf8056478863e6e80fedc2dfc2c072887987426e6f37ee45e4e8/marshmallow-polyfield-5.2.tar.gz" } ], "5.3": [ { "comment_text": "", "digests": { "md5": "f2623b74ff2e15a90ccabff7108b23c1", "sha256": "13c7ebbd6446382f2f8efb9a0286806cf8876a1b24cf346f76aefaeaebea4fdd" }, "downloads": -1, "filename": "marshmallow-polyfield-5.3.tar.gz", "has_sig": false, "md5_digest": "f2623b74ff2e15a90ccabff7108b23c1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10675, "upload_time": "2019-01-06T01:40:29", "url": "https://files.pythonhosted.org/packages/e4/46/485c04a756f0e3185ba382b8f0bfb3cec1916dda2db74522bf52b978e7c1/marshmallow-polyfield-5.3.tar.gz" } ], "5.4": [ { "comment_text": "", "digests": { "md5": "61b861dcc3cd4f294aff7bf7c54dd270", "sha256": "484f308c95b42e20de33480df5d403e2806eb610d6ba70cd0d7eb7114bac474f" }, "downloads": -1, "filename": "marshmallow-polyfield-5.4.tar.gz", "has_sig": false, "md5_digest": "61b861dcc3cd4f294aff7bf7c54dd270", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10705, "upload_time": "2019-01-22T13:21:59", "url": "https://files.pythonhosted.org/packages/a1/0e/1a303faaa4bd01ef348f8ce7d73dfa11dff939b0b358de2bb338a9358bfa/marshmallow-polyfield-5.4.tar.gz" } ], "5.5": [ { "comment_text": "", "digests": { "md5": "e51f3ae47535f7fb12b221b7355e2e0a", "sha256": "0620d3f194428d3b6bb7364b73fc9dce5431234c35d504a9e6c2904c2ff07fad" }, "downloads": -1, "filename": "marshmallow-polyfield-5.5.tar.gz", "has_sig": false, "md5_digest": "e51f3ae47535f7fb12b221b7355e2e0a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8413, "upload_time": "2019-02-27T02:36:36", "url": "https://files.pythonhosted.org/packages/f3/34/c047cd22b61fb2ba4da0bb53c9547ce9e29b9ace8c1bf2d86d27f720f1aa/marshmallow-polyfield-5.5.tar.gz" } ], "5.6": [ { "comment_text": "", "digests": { "md5": "44f1a4da7ede428ad97469a56bd32f24", "sha256": "b18cae5563d854fbd15c05b4ff223e4c0074a02436ad12f74838e614dfd1ebc2" }, "downloads": -1, "filename": "marshmallow-polyfield-5.6.tar.gz", "has_sig": false, "md5_digest": "44f1a4da7ede428ad97469a56bd32f24", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8442, "upload_time": "2019-03-11T01:11:22", "url": "https://files.pythonhosted.org/packages/1f/50/70257a81710ebb1840a09f57cc3d8bdded86e216c444dd34e9bf3f9e803c/marshmallow-polyfield-5.6.tar.gz" } ], "5.7": [ { "comment_text": "", "digests": { "md5": "a612a51595f4084c85c6bb725fc53a2f", "sha256": "963a01e80bca5cb4da42b8d2f7e6e90946257ae22d22ff2ed104a8a863eeb0c6" }, "downloads": -1, "filename": "marshmallow-polyfield-5.7.tar.gz", "has_sig": false, "md5_digest": "a612a51595f4084c85c6bb725fc53a2f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8193, "upload_time": "2019-07-06T15:16:48", "url": "https://files.pythonhosted.org/packages/d7/6c/416e7e529d03362bb57bb4be16a0bb1ada6325b12adf3e31fec4c10ef1b1/marshmallow-polyfield-5.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a612a51595f4084c85c6bb725fc53a2f", "sha256": "963a01e80bca5cb4da42b8d2f7e6e90946257ae22d22ff2ed104a8a863eeb0c6" }, "downloads": -1, "filename": "marshmallow-polyfield-5.7.tar.gz", "has_sig": false, "md5_digest": "a612a51595f4084c85c6bb725fc53a2f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8193, "upload_time": "2019-07-06T15:16:48", "url": "https://files.pythonhosted.org/packages/d7/6c/416e7e529d03362bb57bb4be16a0bb1ada6325b12adf3e31fec4c10ef1b1/marshmallow-polyfield-5.7.tar.gz" } ] }