{ "info": { "author": "Douglas Treadwell", "author_email": "douglas.treadwell@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "Marshmallow Models\n==================\n\n\nInstallation\n------------\n\n```\npip install marshmallow-models\n```\n\n\nContributing\n------------\n\nFeature requests, feedback,\n[issues](https://github.com/douglas-treadwell/marshmallow-models/issues),\nand pull requests are welcome and appreciated.\n\nPlease follow the [Marshmallow Contributing Guidelines](\nhttps://github.com/marshmallow-code/marshmallow/blob/dev/CONTRIBUTING.rst\n).\n\n\nOverview\n--------\n\nInspired by [Schematics](https://github.com/schematics/schematics),\npowered by [Marshmallow](https://github.com/marshmallow-code/marshmallow).\n\nWhereas Marshmallow is an excellent serialization/deserialization\nand validation library, it wasn't intended to be a class or type\ndefinition library, which Schematics was.\n\nThis library provides a Schematics-like Model but\nusing Marshmallow's Fields and validation. This library also\nintentionally maintains the usage style of marshmallow so that\nusers of Marshmallow Schemas will be able to use these Models easily.\n\nUsage\n-----\n\nModels are defined like Schemas, but whereas a Schema is instantiated\nwith parameters and then used to schema.dump(data) or schema.load(data),\nor schema.validate(data),\nModels are instantiated, attributes may be assigned to them, and then\nthey can be .dump()'d, .dumps()'d or .validate()'d.\n\n### Basic Usage\n\n```python\nfrom marshmallow_models import Model\nfrom marshmallow.fields import String, Integer\n\nclass PersonModel(Model):\n name = String(required=True)\n age = Integer(required=True)\n\nperson = PersonModel()\n\nperson.name = 'Tester'\nperson.age = 100\n\n# or equivalently:\nperson = PersonModel({'name': 'Tester', 'age': 100})\n\n# or equivalently:\nperson = PersonModel(name='Tester', age=100)\n\n# throws marshmallow.exceptions.ValidationError if invalid\nperson.validate()\n\nperson.dump().data # {'name': 'Tester', 'age': 100}\n```\n\n### Missing and Default Attributes\n\n```python\nclass PersonModel(Model):\n name = String(missing='Anonymous')\n age = Integer(default=0)\n\nperson = PersonModel()\n\nperson.name # 'Anonymous'\nperson.age # 0\n```\n\nDefault and missing parameters may be provided as they are to\nMarshmallow Schemas.\n\nConstructing a model is treated like\n\"loading\" data (as in, schema.load(data)). If attributes are\nmissing and a `missing` configuration was provided, those values\nwill be assigned to the missing attributes.\n\nReading attributes is treated like \"dumping\" data (as in,\nschema.dump(data)), as are calls to model.dump() and dumps().\nIf a value doesn't exist when read or dumped, the default value\nwill be substituted for that attribute.\n\nIn many cases `default` and `missing` can be used interchangeably\nin the context of Models, but there may be cases where their\ndifferent treatment is meaningful.\n\n### Nested Models\n\nNested models are also supported.\n\n```python\nclass ParentModel(PersonModel):\n child = NestedModel(PersonModel)\n\nparent = ParentModel(name='Tester', age=40, child=dict(name='Child', age=10))\n\nself.assertEqual(parent.child.name, 'Child')\n\nparent.child.name = 'Kid'\n\nself.assertEqual(parent.child.name, 'Kid')\n```\n\nConfiguration\n-------------\n\nMarshmallow Models support the \"class Meta\" configuration method.\n\nAn additional Meta attribute is supported: `strict_constructor`.\n\nIn Marshmallow Schemas, transformation of input data to output data\nwas a single step process. In Marshmallow Models, it might be\nreasonable for users to instantiate a model with incomplete attributes\nand then fill in the attributes before attempting to validate() or\ndump() the data.\n\nBy default, even for Models with `strict = True`\nthe constructor does not raise exceptions for incomplete attributes.\nIf exceptions are wanted in this case, set `strict_constructor = True`.\n\n\n```python\nclass PersonWithStrictConstructorModel(Model):\n class Meta:\n strict_constructor = True\n\n name = String(required=True)\n age = Integer(required=True)\n\nwith self.assertRaises(ValidationError):\n person = PersonWithStrictConstructorModel()\n```\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/douglas-treadwell/marshmallow-models", "keywords": "serialization,rest,json,api,marshal,marshalling,deserialization,validation,schema,model,models,modelling,object,objects", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "marshmallow-models", "package_url": "https://pypi.org/project/marshmallow-models/", "platform": "", "project_url": "https://pypi.org/project/marshmallow-models/", "project_urls": { "Homepage": "https://github.com/douglas-treadwell/marshmallow-models" }, "release_url": "https://pypi.org/project/marshmallow-models/0.2.0/", "requires_dist": [ "marshmallow" ], "requires_python": "", "summary": "Object models with validation and serialization using Marshmallow fields and validators.", "version": "0.2.0" }, "last_serial": 2975290, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "0a05e3a00cea45de088ff57efe7662dc", "sha256": "560cd6e6b9b0096e181125814295d140ff928da6e6a928cc7e3854d9e0a8c33a" }, "downloads": -1, "filename": "marshmallow_models-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "0a05e3a00cea45de088ff57efe7662dc", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5234, "upload_time": "2017-06-13T05:54:46", "url": "https://files.pythonhosted.org/packages/15/25/1031dfa3ce534794195e468f8cbbe88d515f60622daca8aba8d792a0c9b2/marshmallow_models-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a217b36a50c3061de3a0f1f2b1c85933", "sha256": "a8b988bc2dd4a4c72b4e279fb99e8978be5774ac6d25ce5b920655f089290b45" }, "downloads": -1, "filename": "marshmallow_models-0.1.0.tar.gz", "has_sig": false, "md5_digest": "a217b36a50c3061de3a0f1f2b1c85933", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3447, "upload_time": "2017-06-13T05:54:48", "url": "https://files.pythonhosted.org/packages/d6/8c/b7fec6bacdcaf80765524eb9969541ab4e95a7d6ade6afe46ac80fddcab2/marshmallow_models-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "ccb884000a0f0536d394555d6ea47b28", "sha256": "40b275036a26c2fad4bd954a3d8089cb1b9cf6c66bc32c0b8653d1fe44766dad" }, "downloads": -1, "filename": "marshmallow_models-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ccb884000a0f0536d394555d6ea47b28", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8934, "upload_time": "2017-06-24T05:59:19", "url": "https://files.pythonhosted.org/packages/9b/8d/085f84d069bd25cd41fdc1a13e084faa65c6d3cdfc05f7d1f8e3bfdae0c8/marshmallow_models-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6187a5b37d19d58bf5b844215f1190ef", "sha256": "1b2af1c39f67e676cc382b178e31af5fb83db089446b3c45586286c3b9b2c91f" }, "downloads": -1, "filename": "marshmallow-models-0.2.0.tar.gz", "has_sig": false, "md5_digest": "6187a5b37d19d58bf5b844215f1190ef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6183, "upload_time": "2017-06-24T05:59:21", "url": "https://files.pythonhosted.org/packages/e9/69/b2a2c5deda2d0682d369b2d7854e55f838a03e6e7da39d115575eef2dd0b/marshmallow-models-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ccb884000a0f0536d394555d6ea47b28", "sha256": "40b275036a26c2fad4bd954a3d8089cb1b9cf6c66bc32c0b8653d1fe44766dad" }, "downloads": -1, "filename": "marshmallow_models-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ccb884000a0f0536d394555d6ea47b28", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8934, "upload_time": "2017-06-24T05:59:19", "url": "https://files.pythonhosted.org/packages/9b/8d/085f84d069bd25cd41fdc1a13e084faa65c6d3cdfc05f7d1f8e3bfdae0c8/marshmallow_models-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6187a5b37d19d58bf5b844215f1190ef", "sha256": "1b2af1c39f67e676cc382b178e31af5fb83db089446b3c45586286c3b9b2c91f" }, "downloads": -1, "filename": "marshmallow-models-0.2.0.tar.gz", "has_sig": false, "md5_digest": "6187a5b37d19d58bf5b844215f1190ef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6183, "upload_time": "2017-06-24T05:59:21", "url": "https://files.pythonhosted.org/packages/e9/69/b2a2c5deda2d0682d369b2d7854e55f838a03e6e7da39d115575eef2dd0b/marshmallow-models-0.2.0.tar.gz" } ] }