{ "info": { "author": "Arnaud Calmettes", "author_email": "arnaud.calmettes@scality.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "A SerialObject is an object that supports serialization from/to json-like\nobjects (dicts and lists of builtin types).\n\nThe serialization specification is taken from the ``__fields__`` class attribute,\nwhich is on the form:\n\n::\n\n __fields__: {\n FIELD_NAME: FIELD_SPEC\n }\n\nA FIELD_NAME is a string, its only constraint is that it should be a valid\nobject attribute name.\n\nFIELD_SPEC can be:\n\n* Any native type from:\n\n * ``str``\n\n * ``unicode`` (Python2)\n\n * ``int``\n\n * ``float``\n\n * ``bool``\n\n * ``dict``\n\n* A ``SerialObject`` subclass\n\n* ``Choice(val1, val2, ...)`` to form enumerations, values should be of a\n native type (see above).\n\n* ``[FIELD_SPEC]``: a list of objects depicted by the above specs.\n\nAdditionally, SerialObjects support a ``__strict__`` boolean class attribute\n(False by default). When ``__strict__`` == True, an exhaustivity check is performed\nduring (de-)serialization and missing or unknown keys yield errors.\n\nOn Python2, ``str`` instances are automatically coerced to unicode strings.\n\nInstall\n=======\n\n\n``serialobj`` is registered on the PyPi. Simply type the following commands.\n\n::\n\n pip install serialobj\n\n\nAlternatively, you can run the following commands after having cloned the\nsource repository:\n\n::\n\n python setup.py install\n\n\nQuick tutorial\n==============\n\nSimple types and inheritance\n----------------------------\n\nLet us define a very basic Person type that defines two string fields:\n\n::\n\n class Person(SerialObject):\n __fields__ = {\n 'name': str,\n 'job': str\n }\n\n\nNow we can simply deserialize json-compatible data to it, and/or serialize its\ninstances to a json-like structure:\n\n::\n\n >>> person_data = {\n ... 'name': 'Bob',\n ... 'job': 'lumberjack'\n ... }\n >>> bob = Person.deserialize(person_data)\n >>> bob.name\n 'Bob'\n >>> bob.job\n 'lumberjack'\n >>> bob.serialize()\n {'job': 'lumberjack', 'name': 'Bob'}\n\n\nOf course there is more to it than that. Let us subclass our ``Person``, to\ndefine, for instance a ``TeamMate``, which overrides the ``job`` field to allow it\nto be a ``dict`` and to add a new ``str`` field: ``role``.\n\n::\n\n class TeamMate(Person):\n __fields__ = {\n 'role': str,\n 'job': dict\n }\n\nOf course this is a silly example, but this allows us to demonstrate that\ninheriting a `SerialObject` class allows to inherit, override and specialize\nthe structure definition\u00a0:\n\n::\n\n >>> bob2 = TeamMate.deserialize(teammate_data)\n >>> bob2.name\n 'Bob'\n >>> bob2.job\n {'all night': 'sleep', 'all day': 'work'}\n >>> bob2.serialize()\n {'role': 'lumberjack', 'name': 'Bob', 'job': {'all night': 'sleep', 'all day': 'work'}}\n\nIt also allows us to demonstrate that the structure is actually *checked*\nagainst the model: let's try and deserialize our ``teammate_data`` with the\nincompatible ``Person`` model.\n\n::\n\n >>> Person.deserialize(teammate_data)\n Traceback (most recent call last):\n File \"\", line 1, in \n Person.deserialize(teammate_data)\n File \"/home/arnaud/work/serialobj/serialobj.py\", line 242, in deserialize\n for key, val in data.items() if key in cls.__fields__\n File \"/home/arnaud/work/serialobj/serialobj.py\", line 242, in \n for key, val in data.items() if key in cls.__fields__\n File \"/home/arnaud/work/serialobj/serialobj.py\", line 86, in deserialize\n .format(self.cls_.__name__, data))\n serialobj.InvalidTypeError: Expected str, got {'all night': 'sleep', 'all day': 'work'}\n\nIsn't it starting to get interesting?\n\nList of objects\n---------------\n\nLet us spice it up a little bit. What if I want to define a field as a *list of\nstrings*?\n\nWell, there is some sugar for this:\n\n::\n\n class Task(SerialObject):\n __fields__ = {\n 'title': str,\n 'description': str,\n 'checklist': [str]\n }\n\nSee for yourself:\n\n::\n\n >>> data = {\n ... 'title': 'timber some wood',\n ... 'description': '',\n ... 'checklist': [\n ... 'some wood is timbered',\n ... 'the lumberjack is okay',\n ... 'he sleeps all night and works all day'\n ... ]\n ... }\n >>> tsk = Task.deserialize(data)\n >>> tsk.checklist\n ['some wood is timbered', 'the lumberjack is okay', 'he sleeps all night and works all day']\n >>> tsk.checklist.append(\"... and that's it\")\n >>> pprint(tsk.serialize())\n {'checklist': ['some wood is timbered',\n 'the lumberjack is okay',\n 'he sleeps all night and works all day',\n \"... and that's it\"],\n 'description': '',\n 'title': 'timber some wood'}\n\nGoing fancy\n-----------\n\nOf course, all these are the base building blocks to define arbitrarily\ncomplex JSON-API structures:\n\n::\n\n class Team(SerialObject):\n __fields__ = {\n 'name': str,\n 'manager': TeamMate,\n 'members': [TeamMate],\n 'backlog': [Task]\n }\n\n\n COMPLEX_DATA = {\n 'name': \"The good ol' lumberjacks\",\n 'manager': {\n 'name': 'Bob',\n 'role': 'Be okay'\n },\n 'members': [\n {\n 'name': 'Jack',\n 'role': 'sleep all night'\n },\n {\n 'name': 'Barry',\n 'role': 'work all day',\n }],\n 'backlog': [\n {\n 'title': 'timber some wood',\n 'description': '',\n 'checklist': [\n 'some wood is timbered',\n 'the lumberjack is okay',\n 'he sleeps all night and works all day'\n ]\n }]\n }\n\nHere we go:\n\n::\n\n >>> team = Team.deserialize(COMPLEX_DATA)\n >>> team.manager.name\n 'Bob'\n >>> team.manager\n <__console__.TeamMate object at 0x7f34edd2c9a8>\n >>> team.backlog[0]\n <__console__.Task object at 0x7f34edd9b7c8>\n >>> team.backlog[0].title\n 'timber some wood'\n >>> pprint(team.serialize())\n {'backlog': [{'checklist': ['some wood is timbered',\n 'the lumberjack is okay',\n 'he sleeps all night and works all day'],\n 'description': '',\n 'title': 'timber some wood'}],\n 'manager': {'name': 'Bob', 'role': 'Be okay'},\n 'members': [{'name': 'Jack', 'role': 'sleep all night'},\n {'name': 'Barry', 'role': 'work all day'}],\n 'name': \"The good ol' lumberjacks\"}\n\nTesting\n=======\n\nYou can trigger all tests using ``tox``. Tests are currently run for python\n2.7 and 3.5.\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://bitbucket.org/scality/serialobj", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "serialobj", "package_url": "https://pypi.org/project/serialobj/", "platform": "", "project_url": "https://pypi.org/project/serialobj/", "project_urls": { "Homepage": "http://bitbucket.org/scality/serialobj" }, "release_url": "https://pypi.org/project/serialobj/0.8.1/", "requires_dist": [ "chainmap", "six" ], "requires_python": "", "summary": "A library to define serializable classes.", "version": "0.8.1" }, "last_serial": 2562563, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "9eea60bb6faabd2e8f399e99ad21f96a", "sha256": "22d0cbb6fb81912cdd48e1d49ec18854fdb88732aa8cb7adf15ebdb0286ab221" }, "downloads": -1, "filename": "serialobj-0.2-py2-none-any.whl", "has_sig": false, "md5_digest": "9eea60bb6faabd2e8f399e99ad21f96a", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 1757, "upload_time": "2016-11-26T13:00:18", "url": "https://files.pythonhosted.org/packages/28/84/1947ec69fb500c225eafd2f6871b683eaf52cd503606fa4cb01d7317aa69/serialobj-0.2-py2-none-any.whl" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "4d1a61bbf8616b3cd91802e8f980d991", "sha256": "54079c2471099691d220ac9269685a1e3a7ec38dab066c804c779da574b0e261" }, "downloads": -1, "filename": "serialobj-0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4d1a61bbf8616b3cd91802e8f980d991", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9197, "upload_time": "2016-11-28T10:13:30", "url": "https://files.pythonhosted.org/packages/2f/33/99957dc8f324a8a1f777593b374587db83819eea08cacfd9b04d02fadf70/serialobj-0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "efff0704e295cae0d96647d203b05f76", "sha256": "ecd0b651079933da95dffe1371af8874e4002191e8087b2c1252986bc04c7499" }, "downloads": -1, "filename": "serialobj-0.3.tar.gz", "has_sig": false, "md5_digest": "efff0704e295cae0d96647d203b05f76", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3432, "upload_time": "2016-11-26T13:12:38", "url": "https://files.pythonhosted.org/packages/12/18/d039800fac47977d456da7564864ece4279aebec15efe6efc5bd2f5281c8/serialobj-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "5065180a2e1bc129210b2bedb5921831", "sha256": "fe36f5afa0a67d0fec22ecda85806c21316986187dfd323c09e018db9742ab50" }, "downloads": -1, "filename": "serialobj-0.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5065180a2e1bc129210b2bedb5921831", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9308, "upload_time": "2016-12-02T16:30:31", "url": "https://files.pythonhosted.org/packages/9d/3c/6ea844a9f9701fc094eb53cb790d25dc6f861858f1ddd15f4dfdcb015e7c/serialobj-0.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "aa8c1c60dd7f5361c62f9a5c686fb654", "sha256": "cb64ad2042ae93d7a2a08063f44899b39436afdd6f5a3d80ffee51690fad0943" }, "downloads": -1, "filename": "serialobj-0.4.tar.gz", "has_sig": false, "md5_digest": "aa8c1c60dd7f5361c62f9a5c686fb654", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6381, "upload_time": "2016-12-02T16:30:33", "url": "https://files.pythonhosted.org/packages/2a/96/14dcfd0b11c08d906ce3391bbcff2a46dadc3dcadbcff941e9264481bfa7/serialobj-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "b00ef1fc5bb6fcece055c5c6a1838cec", "sha256": "585dc3a0c5ab593b1766b26aa4983307f9ff23aa6e543a39d0331ac5d07c852b" }, "downloads": -1, "filename": "serialobj-0.5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "b00ef1fc5bb6fcece055c5c6a1838cec", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9342, "upload_time": "2016-12-13T07:39:14", "url": "https://files.pythonhosted.org/packages/6b/98/3d7a596a802f6f01f9fc151d396598a700ebafb3d1a2281eb4954063bb93/serialobj-0.5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6ab650ba6b9781190fa97eca84dffea8", "sha256": "7c0834ca9af7e7d1fb0dabf57443ce18e94bcb8847427f69bdbb0e29ec12fe1f" }, "downloads": -1, "filename": "serialobj-0.5.tar.gz", "has_sig": false, "md5_digest": "6ab650ba6b9781190fa97eca84dffea8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6415, "upload_time": "2016-12-13T07:39:18", "url": "https://files.pythonhosted.org/packages/e6/6f/042255626bf50e9132707cd90d61c0607900b3f0c209ae245c231b07954d/serialobj-0.5.tar.gz" } ], "0.6": [ { "comment_text": "", "digests": { "md5": "113df6bcbe32c30c5136050dd107fe83", "sha256": "eae07eb62c0408c8babff0e9e401180a81891d3dd027bf9890edd973d4896fce" }, "downloads": -1, "filename": "serialobj-0.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "113df6bcbe32c30c5136050dd107fe83", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9373, "upload_time": "2016-12-22T09:08:21", "url": "https://files.pythonhosted.org/packages/b6/a4/43d38e3379773a284933e700179fcda95da5f03389bcbeae66f6f83a3c40/serialobj-0.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "60f8cb353aba2bacfb07d9231b847ee7", "sha256": "7c8593b1176fc94d515cbaa3c6482b36da36c0409815c2c435a3f007ebe61aeb" }, "downloads": -1, "filename": "serialobj-0.6.tar.gz", "has_sig": false, "md5_digest": "60f8cb353aba2bacfb07d9231b847ee7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6445, "upload_time": "2016-12-22T09:08:22", "url": "https://files.pythonhosted.org/packages/79/13/3e89c6f32539ab47a6d29dc78e99a973862e7fc3c1b5a4247f2dbda37a73/serialobj-0.6.tar.gz" } ], "0.7": [ { "comment_text": "", "digests": { "md5": "f05658f7431977162e8100d5de897d3d", "sha256": "60942416018d0c99284591d1f904dd1c5300aa67b494a9a93556fc8ce88bedb9" }, "downloads": -1, "filename": "serialobj-0.7-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f05658f7431977162e8100d5de897d3d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9374, "upload_time": "2017-01-02T16:20:04", "url": "https://files.pythonhosted.org/packages/54/f4/afd6e29bd634be0a880c642d2d75fc57e52738104b89e4d3ea140ac52e3f/serialobj-0.7-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ea4fad6ac0fae9be5053bc53e960392c", "sha256": "507f5742be0b535986f6a51ecd019db9d2e6e921f3a1574c88dac01aee8ad556" }, "downloads": -1, "filename": "serialobj-0.7.tar.gz", "has_sig": false, "md5_digest": "ea4fad6ac0fae9be5053bc53e960392c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6441, "upload_time": "2017-01-02T16:20:06", "url": "https://files.pythonhosted.org/packages/92/2b/a492a3d997adeaf69eb757fc63d196b9017da05af5a70e126c1c8b837e99/serialobj-0.7.tar.gz" } ], "0.8": [ { "comment_text": "", "digests": { "md5": "caff07a882a94d2adc9a5debb3870cb0", "sha256": "9a9de103016bdb69cb51e3210c153927f5e95e0c53c5c3316fe6f895cbb24ca8" }, "downloads": -1, "filename": "serialobj-0.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "caff07a882a94d2adc9a5debb3870cb0", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9591, "upload_time": "2017-01-09T12:33:55", "url": "https://files.pythonhosted.org/packages/0c/22/229f976802311b8a3a9fb4ff381f0c4c90bd0782a2551d8f6321e56a443b/serialobj-0.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "48aab9c97123d8b61adaa6c4f992e9c1", "sha256": "bd9194a8f2b29b5f6985f1a149ccf7bfcae2639a4ed6ba80c58f5f2fd4308562" }, "downloads": -1, "filename": "serialobj-0.8.tar.gz", "has_sig": false, "md5_digest": "48aab9c97123d8b61adaa6c4f992e9c1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6653, "upload_time": "2017-01-09T12:33:56", "url": "https://files.pythonhosted.org/packages/e1/cc/bdee59ffeb068a7a0ea60139b769493b283ca578be374e31d52a3d9c033e/serialobj-0.8.tar.gz" } ], "0.8.1": [ { "comment_text": "", "digests": { "md5": "7e3607fac9dae52ad167d672ccfc29dd", "sha256": "9b428adb3523072c77aab01a2f92fdc29835aec9fd86fa2c4cc6f41d0fb37f42" }, "downloads": -1, "filename": "serialobj-0.8.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7e3607fac9dae52ad167d672ccfc29dd", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9625, "upload_time": "2017-01-09T16:32:53", "url": "https://files.pythonhosted.org/packages/95/ef/222a6a7022ac747e3c35d9ac105f27e62aced63e1de8e51fa0f7dae3f1d0/serialobj-0.8.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ac44b091423a089603450afff64cdcc2", "sha256": "a30da360e43169553133b29639fd868ebabf5e9cc38ee2a9ff0757d27ee8303d" }, "downloads": -1, "filename": "serialobj-0.8.1.tar.gz", "has_sig": false, "md5_digest": "ac44b091423a089603450afff64cdcc2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6663, "upload_time": "2017-01-09T16:32:54", "url": "https://files.pythonhosted.org/packages/16/57/daa7187f0be25b2c5ec04f22bf4f38aca3346f8e75298c908e13705fa69c/serialobj-0.8.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7e3607fac9dae52ad167d672ccfc29dd", "sha256": "9b428adb3523072c77aab01a2f92fdc29835aec9fd86fa2c4cc6f41d0fb37f42" }, "downloads": -1, "filename": "serialobj-0.8.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7e3607fac9dae52ad167d672ccfc29dd", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9625, "upload_time": "2017-01-09T16:32:53", "url": "https://files.pythonhosted.org/packages/95/ef/222a6a7022ac747e3c35d9ac105f27e62aced63e1de8e51fa0f7dae3f1d0/serialobj-0.8.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ac44b091423a089603450afff64cdcc2", "sha256": "a30da360e43169553133b29639fd868ebabf5e9cc38ee2a9ff0757d27ee8303d" }, "downloads": -1, "filename": "serialobj-0.8.1.tar.gz", "has_sig": false, "md5_digest": "ac44b091423a089603450afff64cdcc2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6663, "upload_time": "2017-01-09T16:32:54", "url": "https://files.pythonhosted.org/packages/16/57/daa7187f0be25b2c5ec04f22bf4f38aca3346f8e75298c908e13705fa69c/serialobj-0.8.1.tar.gz" } ] }