{ "info": { "author": "RED Interactive Agency", "author_email": "geeks@ff0000.com", "bugtrack_url": null, "classifiers": [], "description": "# cereal-box\n\n## Description\ncereal-box is a serialization library that exposes defined functions through a custom Django template tag and a JSON API.\n\n## Installation\n\nIn your settings, add 'cereal' to INSTALLED_APPS.\n\nIn your urls.py, add\n\n import cereal\n urlpatterns += (patterns('', (r'^api/', include(cereal.urls)))\n \n## Settings\n\n### Managing Requests\n\nWhen using the standard ceral api the ip addresses and the number of requests \nfrom those ip addresses will be kept in the cache. If the number of requests\nfor a specific ip address exceeds the number or requests per the timeout\nthen the user will receive a 503 error response, Service Unavailable. \n\nThe available settings to change this behavior are:\n\n CEREAL_REQUESTS_TIMEOUT, default = 1 (seconds)\n CEREAL_REQUESTS_PER_TIMEOUT, default = 15 (number requests)\n\nIt is highly recommended that you use something fast like Redis or Memcache if you\nuse the timeout view. Otherwise you'll be using the Django cache which defaults\nto your registered database.\n\nIf using the cache and the ip address timeout is not desired, simply write your \nown url:\n\n ('^api/(?P\\w+)/(?P\\w+)', cereal.views.json_api) \n\n### Sorting Keys\n\nIf you want to have the keys output by the api to be sorted simply set the\nfollowing setting:\n\n CEREAL_SORT_KEYS = True\n\nThat will make your api calls human readable. This is suggested only \nfor development as it adds overhead in production.\n\n## Registering a function\n\nThere are a couple of different ways you can do this.\n\n import cereal\n cereal.register(MyModel, [myfunction1, myfunction2])\n cereal.register('my_arbitrary_scope', [myfunction3, myfunction4])\n cereal.register(MyModel, myfunction5)\n cereal.register('my_arbitrary_scope', myfunction6)\n \nModel names will be lower cased. So, MyModel and 'mymodel' are equivalent first arguments.\n \nOr you can use the decorator:\n @cereal.register_for('my_scope') #You could also use a model name here\n def my_function(....)\n ...\n \n### Function details\n\nFunctions take the arguments (scope, **kwargs) where kwargs is all of the arguments passed to cereal.\nTODO: eventually we'd like the request (and other info?) to be passed in here somehow.\n\nFunctions are expected to return a jsonize-able python object. Typically you would use .values() to\ngo from a queryset to a dictionary, although for a less efficient way of getting a similar thing for polymorphic\nrelations, you can use cereal.smart_values(queryset, *keys).\n\n### Custom serializers\n\ncereal.register takes a third argument, a custom serializer. This is called by the default filter*()\nmethods and also can be called manually on a queryset in your registered function with cerial.ize(queryset).\nNote that the serializer is tied to a *model* not to a function. TODO: change this behavior?\n\n## Calling a function\n\nYou can do this in python, with a template tag, or via a JSON API call.\n\n### Python\n\n import cereal\n cereal.call('my_scope', 'my_function', arg1=value1, arg2=value2)\n \n### Template Tag\n\n {% load cereal_tags %}\n {% cereal my_scope.my_function arg1=value1 arg2=value2 as cereals %}\n \nNow 'cereal' will contain whatever python value was returned.\n\n### JSON API\n\nThis uses regular old request parameters. POSTing also works.\n\n curl http://path.to.my.site/api/my_scope/my_function?arg1=value1&arg2=value2\n\nThe result is a jsonified version of the returned python values.\n\n\n## Examples\n#### models.py\n\n\tfrom django.db import models\n\n\tclass Cereal(models.Model): # Nevermind the naming snafu\n\t\tname = models.CharField(max_length=20)\n\t\tsugar_level = models.PositiveIntegerField()\n\t\tdef __unicode__(self): return self.name\n\n\timport cereal\n\tcereal.register(Cereal, [cereal.functions.filter()])\n\n#### Python\n\n\t>>> import cereal\n\t>>> cereal.call('cereal', 'filter', sugar_level=9)\n\t[{'sugar_level': 9, 'id': 1, 'name': u'Lucky Charms'}]\n\n#### Template tag\n\n\t{% load cereal_tags %}\n\t{% cereal cereal.filter sugar_level=9 as cereals %}\n\t\n\n\n\n#### Curl\n\n\tcurl http://127.0.0.1:8000/api/cereal/filter?sugar_level=9\n\t[{\"sugar_level\": 9, \"id\": 1, \"name\": \"Lucky Charms\"}]", "description_content_type": null, "docs_url": null, "download_url": "http://www.github.com/ff0000/cereal-box/", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://www.github.com/ff0000/cereal-box/", "keywords": null, "license": "MIT license", "maintainer": null, "maintainer_email": null, "name": "cereal-box", "package_url": "https://pypi.org/project/cereal-box/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/cereal-box/", "project_urls": { "Download": "http://www.github.com/ff0000/cereal-box/", "Homepage": "http://www.github.com/ff0000/cereal-box/" }, "release_url": "https://pypi.org/project/cereal-box/1.0.4/", "requires_dist": null, "requires_python": null, "summary": "Data feed library for Django models.", "version": "1.0.4" }, "last_serial": 787321, "releases": { "1.0.0": [], "1.0.1": [], "1.0.2": [ { "comment_text": "", "digests": { "md5": "a015b3330e66b7fb0b0020e7c4f3a134", "sha256": "4aed62e319eeb5cfdf17e3add63a7ae51bb911da92340234ee34c87f56f4d603" }, "downloads": -1, "filename": "cereal-box-1.0.2.tar.gz", "has_sig": false, "md5_digest": "a015b3330e66b7fb0b0020e7c4f3a134", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5777, "upload_time": "2011-08-02T20:40:32", "url": "https://files.pythonhosted.org/packages/3d/8b/a9efa45a9e3830299bda3787a07542e9d500e161f20f5bd6700ff7ed9995/cereal-box-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "713c40d14069931923333aa952d0310e", "sha256": "edd04ea8c8f6b8575c6363a16c1223cef8e974fc39ea7586c8dfe49e11dbf608" }, "downloads": -1, "filename": "cereal-box-1.0.3.tar.gz", "has_sig": false, "md5_digest": "713c40d14069931923333aa952d0310e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6455, "upload_time": "2011-08-03T02:48:17", "url": "https://files.pythonhosted.org/packages/79/75/09d088c69e566e76ad3ed81898803bc478024c510a1392d65ac43eaf629a/cereal-box-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "d36eeef506119452849cb64f833c748f", "sha256": "617b58e42c74884da0e11798946ce2b62dd0a079d9b9c7af5b88d9afc5581de1" }, "downloads": -1, "filename": "cereal-box-1.0.4.tar.gz", "has_sig": false, "md5_digest": "d36eeef506119452849cb64f833c748f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7454, "upload_time": "2011-08-04T01:42:16", "url": "https://files.pythonhosted.org/packages/66/87/b5587c2d353648f79a6b3c1a6c64f98e75eaffb756866ce2ffa44023dda5/cereal-box-1.0.4.tar.gz" } ], "v1.0.0": [ { "comment_text": "", "digests": { "md5": "5f2e3833c135ff5c72f6fee52e19450a", "sha256": "2e77177019cf7bcf560c9abf4c0cb149093d46660a9d6f7135aeba98dde2d1e2" }, "downloads": -1, "filename": "cereal-box-v1.0.0.tar.gz", "has_sig": false, "md5_digest": "5f2e3833c135ff5c72f6fee52e19450a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4410, "upload_time": "2011-04-28T18:53:32", "url": "https://files.pythonhosted.org/packages/b5/81/eb55ca2d87fa8a79aff383646a0b0bc1d579695f4b75ea9229efa2c02d87/cereal-box-v1.0.0.tar.gz" } ], "v1.0.1": [ { "comment_text": "", "digests": { "md5": "85c672469123da043b8033f7aab1f47d", "sha256": "4a018dc30f8d47d94d2717a09585155c0541cbb45a121868bd41c6dfbfddd44d" }, "downloads": -1, "filename": "cereal-box-v1.0.1.tar.gz", "has_sig": false, "md5_digest": "85c672469123da043b8033f7aab1f47d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5777, "upload_time": "2011-08-01T23:50:20", "url": "https://files.pythonhosted.org/packages/52/42/fda186805e1f9ad1ef6aaf5207cf69a22e47f5aefcb02553632d0f05d8d0/cereal-box-v1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d36eeef506119452849cb64f833c748f", "sha256": "617b58e42c74884da0e11798946ce2b62dd0a079d9b9c7af5b88d9afc5581de1" }, "downloads": -1, "filename": "cereal-box-1.0.4.tar.gz", "has_sig": false, "md5_digest": "d36eeef506119452849cb64f833c748f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7454, "upload_time": "2011-08-04T01:42:16", "url": "https://files.pythonhosted.org/packages/66/87/b5587c2d353648f79a6b3c1a6c64f98e75eaffb756866ce2ffa44023dda5/cereal-box-1.0.4.tar.gz" } ] }