{ "info": { "author": "Marco Pazzaglia", "author_email": "marco@pazzaglia.me", "bugtrack_url": null, "classifiers": [], "description": "[![Build Status](https://travis-ci.org/marcopaz/pyjo.svg?branch=master)](https://travis-ci.org/marcopaz/pyjo)\n\n# pyjo\n\n> Python JSON Objects\n\nEasily specify and (de)serialize data models in Python.\n\n## Install\n\n```\npip install pyjo\n```\n\n## How to use\n\nFirst you need to create a specification of your models and attributes by using the `Model` and the `Field` classes:\n\n```python\nfrom pyjo import Model, Field, RangeField, EnumField\n\nclass Gender(Enum):\n female = 0\n male = 1\n\nclass Address(Model):\n city = Field(type=str)\n postal_code = Field(type=int)\n address = Field()\n\nclass User(Model):\n name = Field(type=str, repr=True, required=True)\n age = RangeField(min=18, max=120)\n # equivalent to: Field(type=int, validator=lambda x: 18 <= x <= 120)\n gender = EnumField(enum=Gender)\n address = Field(type=Address)\n```\n\nBy default any field is considered optional unless specified with `required` attribute. If required, its presence will be checked during initialization.\n\n```python\nu = User()\n# ...\n# pyjo.exceptions.RequiredField: Field 'name' is required\n```\n\n```python\nUser(name='john', age=18, address=Address(city='NYC'))\n# \n```\n\nWhen the `type` argument is provided, the type of the value assigned to a field will be checked during initialization and assignment:\n\n```python\nUser(name=123)\n# ...\n# pyjo.exceptions.InvalidType: The value of the field 'name' is not of type str, given 123\n```\n\n```python\nu.address.city = 1\n# ...\n# pyjo.exceptions.InvalidType: The value of the field 'city' is not of type str, given 1\n```\n\nIn order to serialize a model you need to call `to_dict`:\n\n```python\nu = User(name='john', age=18, address=Address(city='NYC'))\n\nprint(u.to_dict())\n# {\n# \"name\": \"john\",\n# \"age\": 18,\n# \"address\": {\n# \"city\": \"NYC\"\n# }\n# }\n```\n\nTo create a model starting from its python dictionary representation, use `from_dict`:\n\n```python\nu = User.from_dict({\n \"name\": \"john\",\n \"gender\": \"male\",\n \"age\": 18,\n \"address\": {\n \"city\": \"NYC\"\n }\n })\n\nprint(u)\n# \n\nprint(u.gender)\n# Gender.male\n\nprint(u.address.city)\n# NYC\n```\nNote that `from_dict` will also recreate all the nested pyjo objects.\n\n\n# API Documentation\n\n## Field\nThe `Field` object has several _optional_ arguments:\n\n* `type` specifies the type of the field. If specified, the type will be checked during initialization and assignment\n* `default` specifies the default value for the field. The value of a default can be a function and it will be computed and assigned during the initialization of the object\n* `required` boolean flag to indicate if the field must be specified and can't be `None`, even during assignment (`False` by default)\n* `repr` boolean flag to indicate if the field/value should be shown in the Python representation of the object, when printed (`False` by default)\n* `to_dict`, `from_dict` (functions) to add ad-hoc serialization/deserialization for the field\n* `validator` (function) function that gets called to validate the input (after cast) of a field\n* `cast` (function) cast value of the field (if not empty) before (validation and) assignment\n\n## Model\n\n* `to_dict()`, `from_dict()` serialize/deserialize to/from python dictionaries\n* `to_json()`, `from_json()` shortcuts for `json.dumps(model.to_dict())` and `Model.from_dict(json.loads())`\n\n## Field subclasses\n\nYou can easily create subclasses of `Field` to handle specific types of objects. Several of them are already integrated in pyjo and more are coming (feel free to create a PR to add more):\n\n* `ListField` for fields containing a list of elements\n* `RegexField` for fields containing a string that matches a given regex\n* `RangeField` for fields containing a int with optional minimum/maximum value\n* `DatetimeField` for fields containing a UTC datetime\n\n# Extensions\n\n* [pyjo_mongo](https://github.com/marcopaz/pyjo_mongo) easily interact with MongoDB documents, a lightweight replacement of the `mongoengine` library", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/marcopaz/pyjo/archive/3.2.0.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/marcopaz/pyjo", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "pyjo", "package_url": "https://pypi.org/project/pyjo/", "platform": "", "project_url": "https://pypi.org/project/pyjo/", "project_urls": { "Download": "https://github.com/marcopaz/pyjo/archive/3.2.0.tar.gz", "Homepage": "https://github.com/marcopaz/pyjo" }, "release_url": "https://pypi.org/project/pyjo/3.2.0/", "requires_dist": null, "requires_python": "", "summary": "Python JSON Objects", "version": "3.2.0" }, "last_serial": 5753125, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "576db889849bc5db1153bb2104794ff3", "sha256": "ec5f97cd1e744c575c246a404275a9a9b7e6c650b8ee53aadd322a76fa0e054b" }, "downloads": -1, "filename": "pyjo-0.1.0.tar.gz", "has_sig": false, "md5_digest": "576db889849bc5db1153bb2104794ff3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4074, "upload_time": "2016-11-05T09:53:00", "url": "https://files.pythonhosted.org/packages/a0/96/cca86d36f3a5ce4f36f9ccfc88525f25f0b0a0f0370b7dc6d165af35cdff/pyjo-0.1.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "092acf82dd76f57866f10f220975a1fe", "sha256": "79959ac1765e9d82bbe6e74d899918bda4424895393abb71b74092eaff7a6380" }, "downloads": -1, "filename": "pyjo-0.3.0.tar.gz", "has_sig": false, "md5_digest": "092acf82dd76f57866f10f220975a1fe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6608, "upload_time": "2016-11-05T17:32:57", "url": "https://files.pythonhosted.org/packages/7b/ab/fa940df2ad1aa01ce316f6561c1b417993ba2c8cce85e50464c2c9592cab/pyjo-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "94fb5b1c40c789d9649970570d90095a", "sha256": "69ba946e72019489322da5b46234d91ac14d7b8b1253b91e8a090f7251089437" }, "downloads": -1, "filename": "pyjo-0.3.1.tar.gz", "has_sig": false, "md5_digest": "94fb5b1c40c789d9649970570d90095a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6688, "upload_time": "2016-11-06T08:51:53", "url": "https://files.pythonhosted.org/packages/4c/23/3ccc5f61a513370b65f73c8af083f2c74f55b759ae9cf548e19f9ab52d01/pyjo-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "8ae096830f274ced47a0585659ff5229", "sha256": "280e14ef8a197e0e92e3a5ddbd68e6da659b36833e8040aacd3e8ba2ee84fbb1" }, "downloads": -1, "filename": "pyjo-0.3.2.tar.gz", "has_sig": false, "md5_digest": "8ae096830f274ced47a0585659ff5229", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6695, "upload_time": "2016-11-06T08:59:38", "url": "https://files.pythonhosted.org/packages/15/9e/c2ba5b58d69f2ab9ad55143270947190fca87dad3836ed0756a23d0dd89a/pyjo-0.3.2.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "9ccda21cbf39b35f61b24aa3fb1a3aa5", "sha256": "8885d3a0765f8579a34fbf06e12b13324749c91412bfd397259d705b2e3a1943" }, "downloads": -1, "filename": "pyjo-0.4.0.tar.gz", "has_sig": false, "md5_digest": "9ccda21cbf39b35f61b24aa3fb1a3aa5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6855, "upload_time": "2016-11-06T12:46:59", "url": "https://files.pythonhosted.org/packages/26/96/e76cc47246551564866a7501a9d0676abc9adefdd40b20f92c9d96d1d227/pyjo-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "340213de9336254a637e7572e244b818", "sha256": "db62e43968a5f7198819cd87d1e99a13c91d50014da2ee5a739793612d336de8" }, "downloads": -1, "filename": "pyjo-0.4.1.tar.gz", "has_sig": false, "md5_digest": "340213de9336254a637e7572e244b818", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7836, "upload_time": "2016-11-06T14:55:28", "url": "https://files.pythonhosted.org/packages/37/4b/b5dda74f22e1b787b1f6d37ff5b9ad22cc74fc5e33a33aa5704411a79f92/pyjo-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "53fb3f701a9c9695d6dc54ee12f67504", "sha256": "ce8251fbf6c737149a207d7a8b331f0650533b360862829fff62cbb5d4c8bd92" }, "downloads": -1, "filename": "pyjo-0.4.2.tar.gz", "has_sig": false, "md5_digest": "53fb3f701a9c9695d6dc54ee12f67504", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8247, "upload_time": "2016-11-06T15:50:01", "url": "https://files.pythonhosted.org/packages/21/8f/1a84b6401d0f3406aef23090b87a4a5ef3892e24729912de6972c3f20028/pyjo-0.4.2.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "871859f0c29be413f62d16b9ebd2fb04", "sha256": "43c39b4f64460a9e2bc42391d2b3bde10f8c9d68d53c63a593c8284396e47d95" }, "downloads": -1, "filename": "pyjo-0.5.0.tar.gz", "has_sig": false, "md5_digest": "871859f0c29be413f62d16b9ebd2fb04", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8441, "upload_time": "2016-11-06T17:06:44", "url": "https://files.pythonhosted.org/packages/09/f9/2b082f0f696b31d49d2e152f43b5338cf121360d9f9a70fa95870e47382c/pyjo-0.5.0.tar.gz" } ], "0.5.1": [ { "comment_text": "", "digests": { "md5": "5170e56e77e8a10820ba952a3678c32e", "sha256": "e04ae44ea8481f0f25042eaa35d29542e54636b21a9890c456c09253643ab393" }, "downloads": -1, "filename": "pyjo-0.5.1.tar.gz", "has_sig": false, "md5_digest": "5170e56e77e8a10820ba952a3678c32e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8820, "upload_time": "2016-11-06T22:35:30", "url": "https://files.pythonhosted.org/packages/31/82/79dee9783cb1355f65a40840bc755ca015f2ca890c9394f9de1376ae360d/pyjo-0.5.1.tar.gz" } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "51679a8012ec360588177252409cd474", "sha256": "4fc7a6a8518f2fdcb78524d419fdf31f60cede41d94b7dac18eb588a240c3f23" }, "downloads": -1, "filename": "pyjo-0.6.0.tar.gz", "has_sig": false, "md5_digest": "51679a8012ec360588177252409cd474", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8589, "upload_time": "2016-11-07T08:16:11", "url": "https://files.pythonhosted.org/packages/d7/7d/c7227b03587cea984318d21f37530b17ed25dc3d1ca29ed66ac952ae0a2b/pyjo-0.6.0.tar.gz" } ], "0.6.1": [ { "comment_text": "", "digests": { "md5": "c8c41a75409172cfcd9055701515222e", "sha256": "b6a3c4fe59e72e5ad6baf3d2f2b85c76c522fb98add425214942717abdc59e1d" }, "downloads": -1, "filename": "pyjo-0.6.1.tar.gz", "has_sig": false, "md5_digest": "c8c41a75409172cfcd9055701515222e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8739, "upload_time": "2016-11-08T21:02:12", "url": "https://files.pythonhosted.org/packages/0d/7b/72be44f416cde6b8ecc12243bb5b447d51130e900690f0cba78bf20f35a1/pyjo-0.6.1.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "3a1599a7ccc5572558aa22296e7ab672", "sha256": "478f3af127ceda5f6c9ce68a647e1502447824ef6f90d187385e9a6c27a2851f" }, "downloads": -1, "filename": "pyjo-1.0.0.tar.gz", "has_sig": false, "md5_digest": "3a1599a7ccc5572558aa22296e7ab672", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8955, "upload_time": "2018-01-16T13:06:16", "url": "https://files.pythonhosted.org/packages/3d/1c/4b36b5a24d44ce8ed0ea4270e85d6e875a3afdb70df5c4a6306f9ef03704/pyjo-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "5fe8d3e9b74b815520e27ce47dcc5e1f", "sha256": "0c268b4d0eb4dc36112c0938a6f90e42fb62d7602eb095ab5a5e254dd9e45997" }, "downloads": -1, "filename": "pyjo-1.1.0.tar.gz", "has_sig": false, "md5_digest": "5fe8d3e9b74b815520e27ce47dcc5e1f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9047, "upload_time": "2018-01-18T09:07:50", "url": "https://files.pythonhosted.org/packages/2d/05/bd43eff5d054987b967d65368f37e0d93827f509f8c67caeee5ed03b8802/pyjo-1.1.0.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "62e110b0cfb657f635f92c8d85365081", "sha256": "b383e812d1b9f98198538fe7b0de0b375739eed9536ca5aaaf92c5bb3e3e2c5b" }, "downloads": -1, "filename": "pyjo-1.2.0.tar.gz", "has_sig": false, "md5_digest": "62e110b0cfb657f635f92c8d85365081", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8888, "upload_time": "2018-01-22T09:38:19", "url": "https://files.pythonhosted.org/packages/87/37/fa2490a4d103a367d591ba7a8cf263024594579f774182b1c5696f7d9fb0/pyjo-1.2.0.tar.gz" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "760db89179359546eb9654fd4a3a881f", "sha256": "53dd38655e2b1b585526a14d7f3ac707afe57da8b965a7fce6b00496cc6b4e2f" }, "downloads": -1, "filename": "pyjo-2.0.0.tar.gz", "has_sig": false, "md5_digest": "760db89179359546eb9654fd4a3a881f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10535, "upload_time": "2018-02-14T09:50:57", "url": "https://files.pythonhosted.org/packages/b5/7c/5a0ba3563ff30fe1b35995fa01438c004c45bc2f6a2a5f9d1eb6a085d7ff/pyjo-2.0.0.tar.gz" } ], "2.1.0": [ { "comment_text": "", "digests": { "md5": "6dcdd692c3c6734a5a10b4b79d51906f", "sha256": "c0c73df4d82deb14908d7689e31dad78b8015a436a51b91793f66ad81b90d5c5" }, "downloads": -1, "filename": "pyjo-2.1.0.tar.gz", "has_sig": false, "md5_digest": "6dcdd692c3c6734a5a10b4b79d51906f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10747, "upload_time": "2018-02-20T15:06:12", "url": "https://files.pythonhosted.org/packages/8b/0d/1345690bbfd309dd92bce4da723fe524880d2337984e22793060473f6fdd/pyjo-2.1.0.tar.gz" } ], "2.1.1": [ { "comment_text": "", "digests": { "md5": "20dea61f4950563be8d7de41d6c4231b", "sha256": "2352827172a9b5ea82f6e0d14c865d514a385a2537a126d09fadc87266a129d6" }, "downloads": -1, "filename": "pyjo-2.1.1.tar.gz", "has_sig": false, "md5_digest": "20dea61f4950563be8d7de41d6c4231b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10745, "upload_time": "2018-02-20T15:44:55", "url": "https://files.pythonhosted.org/packages/08/47/424eb8facf23c132ba2827d6a7f582cd8495a2c674a7f2f58f0f9f44d96f/pyjo-2.1.1.tar.gz" } ], "3.0.0": [ { "comment_text": "", "digests": { "md5": "23b63c5e622c2c757921d43de0985b43", "sha256": "e565a52c6c3f618902b13ad6f7248fff856a9fbdcb47c69c86ca1a5b22222ef0" }, "downloads": -1, "filename": "pyjo-3.0.0.tar.gz", "has_sig": false, "md5_digest": "23b63c5e622c2c757921d43de0985b43", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10892, "upload_time": "2018-02-21T10:59:41", "url": "https://files.pythonhosted.org/packages/1d/2a/efa964a46c040674d0129405ff927d060c903b9297717ebbfea4c91d3592/pyjo-3.0.0.tar.gz" } ], "3.0.1": [ { "comment_text": "", "digests": { "md5": "f92a740054608179cd69f3291618c525", "sha256": "10a25dc0b7a2a738f926ecf274365a99eb48116c04b1cf04aa90a151823367e1" }, "downloads": -1, "filename": "pyjo-3.0.1.tar.gz", "has_sig": false, "md5_digest": "f92a740054608179cd69f3291618c525", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11067, "upload_time": "2018-02-21T14:31:46", "url": "https://files.pythonhosted.org/packages/ef/cb/803645bb139cf383579705af156605369d6a46320ec535f0c7ad48104328/pyjo-3.0.1.tar.gz" } ], "3.0.2": [ { "comment_text": "", "digests": { "md5": "5023c870d941678135a46ef26b3c83a9", "sha256": "2263ad709428d262aec4e9c4d0749d51580e212cb96bca40f7232b4a03a90d29" }, "downloads": -1, "filename": "pyjo-3.0.2.tar.gz", "has_sig": false, "md5_digest": "5023c870d941678135a46ef26b3c83a9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11252, "upload_time": "2018-02-28T11:01:23", "url": "https://files.pythonhosted.org/packages/6a/18/caaad751b911289b708021020a7cc68f2a0a44641b7ce824f6109c06d41b/pyjo-3.0.2.tar.gz" } ], "3.1.0": [ { "comment_text": "", "digests": { "md5": "53e9702bedb3282f4e213651deb0dd07", "sha256": "8d69662488fbb7d98abc9e8f1e0f772c36be0ae2d65ef8500a2f5e307a75b352" }, "downloads": -1, "filename": "pyjo-3.1.0.tar.gz", "has_sig": false, "md5_digest": "53e9702bedb3282f4e213651deb0dd07", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11563, "upload_time": "2018-02-28T14:20:39", "url": "https://files.pythonhosted.org/packages/52/09/ef5df3966fd44125da875e37024ea043e8e2f8ef7da37d0707c4cc9b1d62/pyjo-3.1.0.tar.gz" } ], "3.1.1": [ { "comment_text": "", "digests": { "md5": "30201a1b18a7dfdea193f9dceb93ee18", "sha256": "a07c1702d816f88892813cb93a48e2be5bafeb4c70b1f276b02d44973f40fdc9" }, "downloads": -1, "filename": "pyjo-3.1.1.tar.gz", "has_sig": false, "md5_digest": "30201a1b18a7dfdea193f9dceb93ee18", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11545, "upload_time": "2018-03-24T03:39:30", "url": "https://files.pythonhosted.org/packages/95/48/baaaefb36d8df353e83c39345740301fd7a3507dcaaeee9f7c094bb5e70f/pyjo-3.1.1.tar.gz" } ], "3.2.0": [ { "comment_text": "", "digests": { "md5": "f32a95debe7c74781df1802896c390bd", "sha256": "b2f3dd5004422ef1c0e869248f6f87fffbf6faa77e7f047f7702602630bb4b85" }, "downloads": -1, "filename": "pyjo-3.2.0.tar.gz", "has_sig": false, "md5_digest": "f32a95debe7c74781df1802896c390bd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10662, "upload_time": "2019-08-29T14:36:04", "url": "https://files.pythonhosted.org/packages/9c/bf/11ba79154f1c66e0934648cd9ab4afd81d59dedf8c08fbcc56dde713e769/pyjo-3.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f32a95debe7c74781df1802896c390bd", "sha256": "b2f3dd5004422ef1c0e869248f6f87fffbf6faa77e7f047f7702602630bb4b85" }, "downloads": -1, "filename": "pyjo-3.2.0.tar.gz", "has_sig": false, "md5_digest": "f32a95debe7c74781df1802896c390bd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10662, "upload_time": "2019-08-29T14:36:04", "url": "https://files.pythonhosted.org/packages/9c/bf/11ba79154f1c66e0934648cd9ab4afd81d59dedf8c08fbcc56dde713e769/pyjo-3.2.0.tar.gz" } ] }