{ "info": { "author": "Louis Sobel", "author_email": "louis.a.sobel@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "py-entity\n========\n\nBasic Python Entities\n----------------------\n\nAn entity is useful for preparing models for an API or view.\n\nAllows view or API UI specific logic to be removed from models.\n\n### Example\n\nWe have some object..\n\n```python\nclass GeorgeWashington(object):\n id = 1776\n first_name = 'George'\n last_name = 'Washington'\n phone_number = '(202) 456-1111'\n phone_number_private = True\n email = 'prez1@whouse.gov'\n accomplishments = ['president', 'general', 'quarter model', 'woodworking']\n birthday = datetime.datetime(1732, 2, 22, 0, 0)\n```\n\nConverting this object to json would take a bit of work. We need to write\nsome kind of `to_dictionary` method, or a custom encoder. There will stil\nprobably be an issue with the `datetime` (not JSON-encodable) as well as\nthe fact that we want to conditionally include the `phone_number`, as long\nas `phone_number_private` is not `True`.\n\nUsing an `Entity`:\n\n```python\nclass UserEntity(pyentity.Entity):\n _FIELDS_ = [\n 'id',\n 'name',\n 'phone_number',\n 'email',\n 'accomplishments',\n 'birthday',\n ]\n _ALIAS_ = 'user'\n\n def name(self):\n return \"%s %s\" % (self.user.first_name, self.user.last_name)\n\n def birthday(self):\n return self.user.birthday.isoformat()\n\n def phone_number(self):\n if self.user.phone_number_private:\n raise pyentity.SuppressField\n return self.user.phone_number\n```\n\nThen,\n\n```python\ngeorge_entity = UserEntity(GeorgeWashington())\nprint json.dumps(george_entity(), indent=2)\n```\n\n```javascript\n{\n \"email\": \"prez1@whouse.gov\", \n \"accomplishments\": [\n \"president\", \n \"general\", \n \"quarter model\", \n \"woodworking\"\n ], \n \"id\": 1776, \n \"birthday\": \"1732-02-22T00:00:00\", \n \"name\": \"George Washington\"\n}\n```\n\nSomtimes, we want to have different views over the same data. One may be a detailed\ndescription of an object, but some other may just be a summary. Entity inheritance helps here.\n\n```python\nclass SummaryEntity(UserEntity):\n _FIELDS_ = ['name', 'email']\n```\n\nThen,\n\n```python\nsummary_entity = SummaryEntity(GeorgeWashington())\nprint json.dumps(summary_entity(), indent=2)\n```\n\n```javascript\n{\n \"name\": \"George Washington\", \n \"email\": \"prez1@whouse.gov\"\n}\n```", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/louissobel/py-entity", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "pyentity", "package_url": "https://pypi.org/project/pyentity/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pyentity/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/louissobel/py-entity" }, "release_url": "https://pypi.org/project/pyentity/0.2.1/", "requires_dist": null, "requires_python": null, "summary": "Python Serializable Entities", "version": "0.2.1" }, "last_serial": 975319, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "17065e789080f82d7cb47107f587d435", "sha256": "315c6629d91e4a1aa19736d16fd017a3e381867c9200d7418713ecdb75b3b8f7" }, "downloads": -1, "filename": "pyentity-0.1.1.tar.gz", "has_sig": false, "md5_digest": "17065e789080f82d7cb47107f587d435", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5080, "upload_time": "2013-11-13T05:20:49", "url": "https://files.pythonhosted.org/packages/c0/3d/5d4e309552b1705172e44b1eabdd073c819bb5a37ec84874b4eb79a98a92/pyentity-0.1.1.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "784dcbbc76f3c800717d062e6412d7cd", "sha256": "cedc95e287cf7f0b17d900def565671dac56e2f9b3ae7fdfbf783121a1003b81" }, "downloads": -1, "filename": "pyentity-0.2.1.tar.gz", "has_sig": false, "md5_digest": "784dcbbc76f3c800717d062e6412d7cd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5890, "upload_time": "2014-01-21T00:52:31", "url": "https://files.pythonhosted.org/packages/96/32/a3daedfe9863acc88a488d93e92055eddd5c475f45f499a99f0c298e0c10/pyentity-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "784dcbbc76f3c800717d062e6412d7cd", "sha256": "cedc95e287cf7f0b17d900def565671dac56e2f9b3ae7fdfbf783121a1003b81" }, "downloads": -1, "filename": "pyentity-0.2.1.tar.gz", "has_sig": false, "md5_digest": "784dcbbc76f3c800717d062e6412d7cd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5890, "upload_time": "2014-01-21T00:52:31", "url": "https://files.pythonhosted.org/packages/96/32/a3daedfe9863acc88a488d93e92055eddd5c475f45f499a99f0c298e0c10/pyentity-0.2.1.tar.gz" } ] }