{ "info": { "author": "Maxim Kulkin", "author_email": "maxim.kulkin@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "=======================\nmarshmallow-oneofschema\n=======================\n\n.. image:: https://dev.azure.com/sloria/sloria/_apis/build/status/marshmallow-code.marshmallow-oneofschema?branchName=master\n :target: https://dev.azure.com/sloria/sloria/_build/latest?definitionId=13&branchName=master\n :alt: Build Status\n\n.. image:: https://badgen.net/badge/marshmallow/3\n :target: https://marshmallow.readthedocs.io/en/latest/upgrading.html\n :alt: marshmallow 3 compatible\n\nAn extension to marshmallow to support schema (de)multiplexing.\n\nmarshmallow is a fantastic library for serialization and deserialization of data.\nFor more on that project see its `GitHub `_\npage or its `Documentation `_.\n\nThis library adds a special kind of schema that actually multiplexes other schemas\nbased on object type. When serializing values, it uses get_obj_type() method\nto get object type name. Then it uses ``type_schemas`` name-to-Schema mapping\nto get schema for that particular object type, serializes object using that\nschema and adds an extra field with name of object type. Deserialization is reverse.\n\nInstalling\n----------\n\n::\n\n $ pip install marshmallow-oneofschema\n\nExample\n-------\n\nThe code below demonstrates how to set up a polymorphic schema. 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 import marshmallow\n import marshmallow.fields\n from marshmallow_oneofschema import OneOfSchema\n\n\n class Foo:\n def __init__(self, foo):\n self.foo = foo\n\n\n class Bar:\n def __init__(self, bar):\n self.bar = bar\n\n\n class FooSchema(marshmallow.Schema):\n foo = marshmallow.fields.String(required=True)\n\n @marshmallow.post_load\n def make_foo(self, data, **kwargs):\n return Foo(**data)\n\n\n class BarSchema(marshmallow.Schema):\n bar = marshmallow.fields.Integer(required=True)\n\n @marshmallow.post_load\n def make_bar(self, data, **kwargs):\n return Bar(**data)\n\n\n class MyUberSchema(OneOfSchema):\n type_schemas = {\"foo\": FooSchema, \"bar\": BarSchema}\n\n def get_obj_type(self, obj):\n if isinstance(obj, Foo):\n return \"foo\"\n elif isinstance(obj, Bar):\n return \"bar\"\n else:\n raise Exception(\"Unknown object type: {}\".format(obj.__class__.__name__))\n\n\n MyUberSchema().dump([Foo(foo=\"hello\"), Bar(bar=123)], many=True)\n # => [{'type': 'foo', 'foo': 'hello'}, {'type': 'bar', 'bar': 123}]\n\n MyUberSchema().load(\n [{\"type\": \"foo\", \"foo\": \"hello\"}, {\"type\": \"bar\", \"bar\": 123}], many=True\n )\n # => [Foo('hello'), Bar(123)]\n\nBy default get_obj_type() returns obj.__class__.__name__, so you can just reuse that\nto save some typing:\n\n.. code:: python\n\n class MyUberSchema(OneOfSchema):\n type_schemas = {\"Foo\": FooSchema, \"Bar\": BarSchema}\n\nYou can customize type field with `type_field` class property:\n\n.. code:: python\n\n class MyUberSchema(OneOfSchema):\n type_field = \"object_type\"\n type_schemas = {\"Foo\": FooSchema, \"Bar\": BarSchema}\n\n\n MyUberSchema().dump([Foo(foo=\"hello\"), Bar(bar=123)], many=True)\n # => [{'object_type': 'Foo', 'foo': 'hello'}, {'object_type': 'Bar', 'bar': 123}]\n\nYou can use resulting schema everywhere marshmallow.Schema can be used, e.g.\n\n.. code:: python\n\n import marshmallow as m\n import marshmallow.fields as f\n\n\n class MyOtherSchema(m.Schema):\n items = f.List(f.Nested(MyUberSchema))\n\nLicense\n-------\n\nMIT licensed. See the bundled `LICENSE `_ file for more details.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/marshmallow-code/marshmallow-oneofschema", "keywords": "serialization,deserialization,json,marshal,marshalling,schema,validation,multiplexing,demultiplexing,polymorphic", "license": "MIT", "maintainer": "Steven Loria", "maintainer_email": "sloria1@gmail.com", "name": "marshmallow-oneofschema", "package_url": "https://pypi.org/project/marshmallow-oneofschema/", "platform": "", "project_url": "https://pypi.org/project/marshmallow-oneofschema/", "project_urls": { "Homepage": "https://github.com/marshmallow-code/marshmallow-oneofschema" }, "release_url": "https://pypi.org/project/marshmallow-oneofschema/2.0.1/", "requires_dist": [ "marshmallow (<4.0.0,>=3.0.0rc6)", "pytest ; extra == 'dev'", "mock ; extra == 'dev'", "flake8 (==3.7.8) ; extra == 'dev'", "flake8-bugbear (==19.3.0) ; extra == 'dev'", "pre-commit (~=1.17.0) ; extra == 'dev'", "tox ; extra == 'dev'", "flake8 (==3.7.8) ; extra == 'lint'", "flake8-bugbear (==19.3.0) ; extra == 'lint'", "pre-commit (~=1.17.0) ; extra == 'lint'", "pytest ; extra == 'tests'", "mock ; extra == 'tests'" ], "requires_python": ">=3.5", "summary": "marshmallow multiplexing schema", "version": "2.0.1" }, "last_serial": 5531677, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "fc2cd83e3fa86be53768895d6fbf0f11", "sha256": "d1d6dc6d373a29af9a97ebe9ddf5bc2d39620a5c29ded38b4530f71641735203" }, "downloads": -1, "filename": "marshmallow-oneofschema-1.0.tar.gz", "has_sig": false, "md5_digest": "fc2cd83e3fa86be53768895d6fbf0f11", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4372, "upload_time": "2016-03-15T05:18:04", "url": "https://files.pythonhosted.org/packages/fc/54/91e9e1e1587ca96a779cdce7e97545b421a0b5eccdb2d8dbe9fb567ac7a1/marshmallow-oneofschema-1.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "11d684ddbf27f4e1cbdbc455bf6f4f25", "sha256": "1ffb961d160b7fcb09ef36940ae91ca693ed80595bb532ef32473dbfa99d85c5" }, "downloads": -1, "filename": "marshmallow_oneofschema-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "11d684ddbf27f4e1cbdbc455bf6f4f25", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 8033, "upload_time": "2016-08-12T00:27:28", "url": "https://files.pythonhosted.org/packages/5c/25/72346c5654823572a725d06c14ffc96f328f5434b70c9f42054bd37a30d8/marshmallow_oneofschema-1.0.1-py2.py3-none-any.whl" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "d4d4618b4e5dbd71a3c5658a75a42672", "sha256": "148925c7f86f679737cea14f3720d2f9edf640db30c0d37239b23878eeae7407" }, "downloads": -1, "filename": "marshmallow_oneofschema-1.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d4d4618b4e5dbd71a3c5658a75a42672", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 8058, "upload_time": "2016-08-12T01:25:46", "url": "https://files.pythonhosted.org/packages/93/bc/08b6a1fa0b42637eaf49dac671588b03aa33f65ece343c0b38ab5d961920/marshmallow_oneofschema-1.0.2-py2.py3-none-any.whl" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "3e30b7460afb072c7356aacc13186a39", "sha256": "d8dd37b5802610e4790409c10bcd8d6fb5de8733bed4144980078e4478afb5b9" }, "downloads": -1, "filename": "marshmallow_oneofschema-1.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "3e30b7460afb072c7356aacc13186a39", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8151, "upload_time": "2016-11-04T18:43:45", "url": "https://files.pythonhosted.org/packages/68/95/7a1002f21810fd8c880a02668f6e2e12f2eed0be7e09dbbf59351e12435b/marshmallow_oneofschema-1.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3211aabaa0ad6ad99aefcc37a94475ed", "sha256": "62df51f0497edcf3954bcb630cda7cae6a294517ab575aa56cdd618058334c96" }, "downloads": -1, "filename": "marshmallow-oneofschema-1.0.3.tar.gz", "has_sig": false, "md5_digest": "3211aabaa0ad6ad99aefcc37a94475ed", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4822, "upload_time": "2016-11-04T18:43:48", "url": "https://files.pythonhosted.org/packages/61/b9/e07b6006cea93b0f023f645fac9decfffea8b56becaed8c0dc2348966a5f/marshmallow-oneofschema-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "b688853fe1e0ed4782c60c688b236dee", "sha256": "72b90c0fe36afd5215c0abfea6ba1c89c12dd375bbbe469fc83916dc9e2e005b" }, "downloads": -1, "filename": "marshmallow_oneofschema-1.0.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "b688853fe1e0ed4782c60c688b236dee", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8188, "upload_time": "2017-04-26T00:54:05", "url": "https://files.pythonhosted.org/packages/1f/43/d1a332ed8b9c74ac9df596d77dc75dfe87c37026613b1f72d04550ef524d/marshmallow_oneofschema-1.0.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "da5a1bd763ae55f133b152c96183694a", "sha256": "1411934066858a71805c3f98dcbdcd24db52e28003988b5515e1189c642524d3" }, "downloads": -1, "filename": "marshmallow-oneofschema-1.0.4.tar.gz", "has_sig": false, "md5_digest": "da5a1bd763ae55f133b152c96183694a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4870, "upload_time": "2017-04-26T00:54:07", "url": "https://files.pythonhosted.org/packages/1b/31/3977a147d33cc71468ea3509a70c0db78c746bef1bcb3ee808c8670b14a3/marshmallow-oneofschema-1.0.4.tar.gz" } ], "1.0.5": [ { "comment_text": "", "digests": { "md5": "958c118f8ad7eb57be2eaabd741426a0", "sha256": "a8b7db820304bd8d9d954f5fe6522bfa89c003dac12fa0e76edddc244901f2f8" }, "downloads": -1, "filename": "marshmallow_oneofschema-1.0.5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "958c118f8ad7eb57be2eaabd741426a0", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8231, "upload_time": "2017-06-21T04:37:54", "url": "https://files.pythonhosted.org/packages/48/40/1e80ebeacd21047389a74541f6784abe1a98dc059e002a10a620b84f1a9e/marshmallow_oneofschema-1.0.5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "44fc1a776fae82099a97c854c930861b", "sha256": "5b645dcb582657362362c6ad9fce5afa5ac31837cac2fe63b8eabf47995dd944" }, "downloads": -1, "filename": "marshmallow-oneofschema-1.0.5.tar.gz", "has_sig": false, "md5_digest": "44fc1a776fae82099a97c854c930861b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4944, "upload_time": "2017-06-21T04:37:56", "url": "https://files.pythonhosted.org/packages/44/3d/7c6c4ee7fcf87349d1f020707a6961f7850b687a297b17066016cbd50dcb/marshmallow-oneofschema-1.0.5.tar.gz" } ], "1.0.6": [ { "comment_text": "", "digests": { "md5": "5cad0850327183f90d763d108f1481a7", "sha256": "90bf088def670629f7a4be7b433b2fd8265a090a085700b1656066431d68c5ac" }, "downloads": -1, "filename": "marshmallow_oneofschema-1.0.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5cad0850327183f90d763d108f1481a7", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5479, "upload_time": "2019-07-14T17:59:40", "url": "https://files.pythonhosted.org/packages/91/4d/5cffc2e19796b2abcc278da5670dfca3599bbfe3d53b18d8fd6a827a3946/marshmallow_oneofschema-1.0.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5c0d548be20a33e35b4a16c3d53ae8bf", "sha256": "8d9bfd53d0d2e287fdf7caf999a108bc12c7ab1bf09bc8c91ad99ed331506171" }, "downloads": -1, "filename": "marshmallow-oneofschema-1.0.6.tar.gz", "has_sig": false, "md5_digest": "5c0d548be20a33e35b4a16c3d53ae8bf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5067, "upload_time": "2019-07-14T17:59:42", "url": "https://files.pythonhosted.org/packages/29/6c/7dc2885a4a86f7bb1e8c0b1262dc0ce137ecff6e1c0e4178d8e0290c59c5/marshmallow-oneofschema-1.0.6.tar.gz" } ], "2.0.0.post0": [ { "comment_text": "", "digests": { "md5": "f3b083e32c89ce7f2e68efa092ee59b4", "sha256": "30d1fbb4858b79af4adb8ffc3bff2e352c4c0bbb62bd87f69d8432589a37ac47" }, "downloads": -1, "filename": "marshmallow_oneofschema-2.0.0.post0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f3b083e32c89ce7f2e68efa092ee59b4", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.5", "size": 5781, "upload_time": "2019-05-30T03:59:36", "url": "https://files.pythonhosted.org/packages/f1/49/b68610394a2da31e73372a423bef51d71a1dbfbf6ad3c3ff134bdbae7325/marshmallow_oneofschema-2.0.0.post0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fba8f46a59123d35bb7503280feafebd", "sha256": "0c0eaee7a81ca02899e879f69582e738054c126a291ef2636b6b70e4e807aa5a" }, "downloads": -1, "filename": "marshmallow-oneofschema-2.0.0.post0.tar.gz", "has_sig": false, "md5_digest": "fba8f46a59123d35bb7503280feafebd", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5671, "upload_time": "2019-05-30T03:59:37", "url": "https://files.pythonhosted.org/packages/e3/60/e7d728ea1063ecc176bbf64641ee260a71ad1a7f0e3d449950842d054ec1/marshmallow-oneofschema-2.0.0.post0.tar.gz" } ], "2.0.0b1": [ { "comment_text": "", "digests": { "md5": "39321f896fb9dd166eedad07c51ba908", "sha256": "2e185d97df6ad4a8ff245cc4f9380a225320fd731c555f0e04beff331a161206" }, "downloads": -1, "filename": "marshmallow_oneofschema-2.0.0b1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "39321f896fb9dd166eedad07c51ba908", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6196, "upload_time": "2018-10-16T23:08:09", "url": "https://files.pythonhosted.org/packages/b4/28/044690165933305d85f84592f7ec793c4191b6263ffbfee7a3755a772d3e/marshmallow_oneofschema-2.0.0b1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6f3a57c7eb777c1b3b919539523a4fb2", "sha256": "f7d7a612618c28aa38cfba496c20acc0218587d60fdcd2beaac2af2ce279d58c" }, "downloads": -1, "filename": "marshmallow-oneofschema-2.0.0b1.tar.gz", "has_sig": false, "md5_digest": "6f3a57c7eb777c1b3b919539523a4fb2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5236, "upload_time": "2018-10-16T23:08:11", "url": "https://files.pythonhosted.org/packages/58/ee/44fe23b1b9e0cf9f3657932be89a0d6ae3c9d1db43f09f80254842675332/marshmallow-oneofschema-2.0.0b1.tar.gz" } ], "2.0.0b2": [ { "comment_text": "", "digests": { "md5": "b35d17128f2ceb11801873b2158361c8", "sha256": "d4478eb63c47557738b1832e5fd06dd72db97eed4d7f82529d44992298f6caca" }, "downloads": -1, "filename": "marshmallow_oneofschema-2.0.0b2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "b35d17128f2ceb11801873b2158361c8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6289, "upload_time": "2018-10-25T05:59:22", "url": "https://files.pythonhosted.org/packages/d6/e4/9e95f3aeb376dd1e6ca65c72985e26d65e0124fe4d2d9623ad7d28fc1bc8/marshmallow_oneofschema-2.0.0b2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e174c01d83e13ba35b9192872506c758", "sha256": "ca0464ffce7f442db2682e32b14ff1f8596dbee7ca97fe94fccc8e4c3cdc1343" }, "downloads": -1, "filename": "marshmallow-oneofschema-2.0.0b2.tar.gz", "has_sig": false, "md5_digest": "e174c01d83e13ba35b9192872506c758", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5307, "upload_time": "2018-10-25T05:59:23", "url": "https://files.pythonhosted.org/packages/2c/bb/44ce19030dbae7c298e063180a00b85184c1eea7dc247829f0a3deff8dd7/marshmallow-oneofschema-2.0.0b2.tar.gz" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "a72c6271fd2a1bb5115206e9a27df0de", "sha256": "29673bcc415f4a2098e273bf3c8229bc1a33e91378885eac90b06943bd626110" }, "downloads": -1, "filename": "marshmallow_oneofschema-2.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a72c6271fd2a1bb5115206e9a27df0de", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.5", "size": 5734, "upload_time": "2019-07-14T18:10:52", "url": "https://files.pythonhosted.org/packages/7a/f3/da71ec4c539b6b5e16f1988fc46d8ea3374e258ef79fb5a7d88478fb922f/marshmallow_oneofschema-2.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "17bcbffa460a168471d1e0c85d0cb7db", "sha256": "b88daa4f2de249e0a51a617aa09490f896acaddef6f6cf97dda78218c5abb86f" }, "downloads": -1, "filename": "marshmallow-oneofschema-2.0.1.tar.gz", "has_sig": false, "md5_digest": "17bcbffa460a168471d1e0c85d0cb7db", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5770, "upload_time": "2019-07-14T18:10:54", "url": "https://files.pythonhosted.org/packages/a7/6f/709688e46ae54eb87e618c5a3a56aae125da0eafdaa3adc661c8bf91ddc8/marshmallow-oneofschema-2.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a72c6271fd2a1bb5115206e9a27df0de", "sha256": "29673bcc415f4a2098e273bf3c8229bc1a33e91378885eac90b06943bd626110" }, "downloads": -1, "filename": "marshmallow_oneofschema-2.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a72c6271fd2a1bb5115206e9a27df0de", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.5", "size": 5734, "upload_time": "2019-07-14T18:10:52", "url": "https://files.pythonhosted.org/packages/7a/f3/da71ec4c539b6b5e16f1988fc46d8ea3374e258ef79fb5a7d88478fb922f/marshmallow_oneofschema-2.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "17bcbffa460a168471d1e0c85d0cb7db", "sha256": "b88daa4f2de249e0a51a617aa09490f896acaddef6f6cf97dda78218c5abb86f" }, "downloads": -1, "filename": "marshmallow-oneofschema-2.0.1.tar.gz", "has_sig": false, "md5_digest": "17bcbffa460a168471d1e0c85d0cb7db", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5770, "upload_time": "2019-07-14T18:10:54", "url": "https://files.pythonhosted.org/packages/a7/6f/709688e46ae54eb87e618c5a3a56aae125da0eafdaa3adc661c8bf91ddc8/marshmallow-oneofschema-2.0.1.tar.gz" } ] }