{ "info": { "author": "Cam Sa\u00fcl", "author_email": "cammsaul@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development" ], "description": "Django REST Params\r\n==================\r\n\r\nFunction decorator to specify and validate parameters for API calls.\r\nInvalid params will automatically return a useful error message;\r\nvalidated params are passed to the wrapped function as kwargs.\r\n\r\n.. code:: bash\r\n\r\n pip install django-rest-params==1.0.2\r\n\r\nA Few Examples\r\n--------------------\r\n\r\nSpecify the types of parameters, and check that they are within acceptable ranges:\r\n\r\n.. code:: python\r\n\r\n from django_rest_params.decorators import params\r\n\r\n @api_view(['GET'])\r\n @params(latitude=float, latitude__gte=-90.0, latitude__lte=90.0,\r\n longitude=float, longitude__gte=-180.0, longitude__lte=180.0)\r\n def get_something(request, latitude, longitude):\r\n # If latitude/longitude are missing or out of range, user will get an error message.\r\n # If we get here, we know they're valid\r\n pass\r\n\r\nCreate optional params with default values. Django REST Params supports POST params as well:\r\n\r\n.. code:: python\r\n\r\n @api_view(['POST'])\r\n @params(offset=int, offset__default=0)\r\n def paged_api_call(request, offset):\r\n # if offset isn't specified, default value is used\r\n pass\r\n\r\nDjango REST Params works with ViewSets as well as request functions.\r\n\r\n.. code:: python\r\n\r\n class ShirtsViewSet(viewsets.GenericViewSet):\r\n\r\n @params(colors=('red','blue','green','yellow'), colors__many=True,\r\n colors__optional=True, colors__name='color_filter')\r\n def get_shirts(self, request, colors):\r\n # Handle API calls like these:\r\n # /shirts?color_filter=red __name lets you use a function param name different from the API param name\r\n # /shirts?color_filter=yellow,blue __many lets you pass multiple values\r\n # /shirts __optional will set colors to None if it isn't specified\r\n # /shirts?color_filter=black ERROR! This will return an error stating black is invalid, and listing the valid options\r\n pass\r\n\r\nOptions\r\n=======\r\n\r\nTYPE\r\n----\r\nSpecify the type of a param:\r\n\r\n.. code:: python\r\n\r\n latitude=float\r\n\r\nvalid options are:\r\n - int\r\n - float\r\n - bool (1/true are considered True, and 0/false False; this is not case-sensitive)\r\n - str/unicode\r\n - tuple/list/set/frozenset (which will be treated as a list of valid options)\r\n - a django Model subclass (in which case the param will be treated as a PK to that Model)\r\n\r\nGT/LT/GTE/LTE\r\n-------------\r\nAutomatically check that a param falls within a certain range. Valid for float, int, or Model PK, which all do numerical comparisons.\r\n\r\n.. code:: python\r\n\r\n latitude__gte=-90.0\r\n latitude__lte=90.0\r\n\r\nLENGTH__LT/GT/LTE/GTE/EQ\r\n------------------------\r\nOnly valid for str params. Check the length of the str\r\n\r\n.. code:: python\r\n\r\n description__length__lt=256\r\n country_code__length__eq=2\r\n\r\nOPTIONAL\r\n--------\r\n\r\n.. code:: python\r\n\r\n latitude__optional=True # same as latitude__default=None\r\n\r\nDefault is False; if set to True, this param will be checked for validity (it will still return a 400 if it doesn't pass gte checks, for example),\r\nbut will be passed to the wrapped function as None if it wasn't specified.\r\n\r\nDEFAULT\r\n-------\r\n\r\n.. code:: python\r\n\r\n sort_by=('messages_count', 'most_recent')\r\n sort_by__default='messages_count'\r\n\r\nImplies that this param is optional.\r\nSpecify a default value for this param if it isn't specified.\r\n\r\nNAME\r\n----\r\nBy default, we'll look for a param with the same name as the kwargs, e.g.\r\n\r\n.. code:: python\r\n\r\n user_id=User # User is a Django model. Look for user_id param, fetch corresponding User, pass to wrapped fn as user_id\r\n\r\nBut sometimes it makes more sense to call such a param 'user' locally, so you can do:\r\n\r\n.. code:: python\r\n\r\n user=User, user__name='user_id' # look for user_id, assign to user\r\n\r\nMANY\r\n----\r\n\r\n.. code:: python\r\n\r\n users=int # param 'users=1' is ok, 'users=1,2' is not\r\n users__many=True # param 'users=1,2' will return tuple of (1, 2), 'users=1' will return (1)\r\n\r\nAllow User to (optionally) specify params as CSV (GET) or Array (JSON POST)\r\nIf many==True, the params will be returned as a tuple regardless of whether or not there was only one param\r\n\r\nDEFERRED\r\n--------\r\n.. code:: python\r\n\r\n user__deferred=True\r\n\r\nBy default, Django REST Params will retrieve an object like this:\r\n\r\n.. code:: python\r\n\r\n User.objects.only('id').get(id=user_id) # all fields except for 'id' are deferred\r\n\r\nUsually, this is preferrable, since we usually don't need to fetch the entire object from the DB, and it is significantly faster than doing so.\r\nBy setting __deferred to False, Django REST Params will change the object retrieval call to this:\r\n\r\n.. code:: python\r\n\r\n User.objects.get(id=user_id) # All fields are fetched\r\n\r\nFIELD\r\n-----\r\n\r\n.. code:: python\r\n\r\n category = Category # by default, do Category.get(id=category)\r\n category__field='name' # instead, do Category.get(name=category)\r\n\r\nApplies to Django models only. By default, we treat the param as an ID; instead, you can treat it as something else, e.g. 'name'\r\n\r\nMETHOD\r\n------\r\nValid methods for passing this param. Default is 'POST' for POST/PUT requests and GET for all others\r\n\r\n.. code:: python\r\n\r\n user__method='GET' # GET only\r\n user__method=('GET', 'POST') # allow either source\r\n\r\nExtra Customization\r\n===================\r\n\r\nYou can tweak some behavior by setting adding a 'DJANGO_REST_PARAMS' dict to your Django settings module:\r\n\r\n.. code:: python\r\n\r\n DJANGO_REST_PARAMS: {\r\n 'TRUE_VALUES': ('1', 'true'), # tuple of case-insensitive string values we'll accept as True for a param of type bool.\r\n 'FALSE_VALUES': ('0', 'false'), # string values that are considered false\r\n }\r\n\r\n\r\nTests\r\n=====\r\n\r\nRun the (fairly extensive) unit tests:\r\n\r\n.. code:: bash\r\n\r\n make test\r\n\r\nMock classes are used to simulate Django models / managers / Django REST Framework requests, so these tests don't actually need to run inside a Django app.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/camsaul/django-rest-params", "keywords": "rest,django,api,params,parameters,djangorestframework,decorator", "license": "3-Clause BSD", "maintainer": "", "maintainer_email": "", "name": "django-rest-params", "package_url": "https://pypi.org/project/django-rest-params/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-rest-params/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/camsaul/django-rest-params" }, "release_url": "https://pypi.org/project/django-rest-params/1.0.2/", "requires_dist": null, "requires_python": null, "summary": "Function decorator for Django REST Framework for specifying and constraining API parameters.", "version": "1.0.2" }, "last_serial": 2021722, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "8a1286e735a65ea61f01979137f718df", "sha256": "0624087224d26d1ea6796f5cf38682a54dde591ad364583d72cb48b98e1a1c19" }, "downloads": -1, "filename": "django_rest_params-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8a1286e735a65ea61f01979137f718df", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11675, "upload_time": "2014-09-17T01:15:02", "url": "https://files.pythonhosted.org/packages/2e/6c/eead27a5e3a4210ba2fa118ab7aa0e8335906d881f7262ba7763f344b483/django_rest_params-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "749b12c2c9278d1805f82d5b05ad01e5", "sha256": "8733be90a8d07ab07131abc008cb751193f38b670d3c835066f15784959bfac3" }, "downloads": -1, "filename": "django-rest-params-1.0.0.tar.gz", "has_sig": false, "md5_digest": "749b12c2c9278d1805f82d5b05ad01e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6502, "upload_time": "2014-09-17T01:14:59", "url": "https://files.pythonhosted.org/packages/32/b1/d894a65fd9ed11b96439af6d44dc3c47841479128ba3ea2d830a8476e10c/django-rest-params-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "be3e2e376fe5764b1557a89a92a966dd", "sha256": "9e8fa7d9464467f81272adaa4f6a146bd1b1dbde68925ae6629cc9da2f1e72ba" }, "downloads": -1, "filename": "django_rest_params-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "be3e2e376fe5764b1557a89a92a966dd", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11745, "upload_time": "2014-10-19T14:07:30", "url": "https://files.pythonhosted.org/packages/52/2c/b27b9f39d2f1fc8d6b3e43a090bbb9bcc2d1edde0c7313e396d90137cd49/django_rest_params-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fee9985d7b8c1e31d6c3e6904031ec25", "sha256": "d0f0a6b5996a30a5283cfa1a164b1fa637b9a86d39d3dbb3154d0c091b35c68c" }, "downloads": -1, "filename": "django-rest-params-1.0.1.tar.gz", "has_sig": false, "md5_digest": "fee9985d7b8c1e31d6c3e6904031ec25", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6529, "upload_time": "2014-10-19T14:07:26", "url": "https://files.pythonhosted.org/packages/ad/47/cae5503861a40644b90805d399eb3727acb3bc8b373ce5738467d9ef2e58/django-rest-params-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "5f65f75e05933a4957e9fb6f01ca4679", "sha256": "248fe5fcf2e8d24f958d738b33a469b2cbe1f1b0db20082e014abda214f693b8" }, "downloads": -1, "filename": "django_rest_params-1.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5f65f75e05933a4957e9fb6f01ca4679", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12367, "upload_time": "2014-10-19T15:00:57", "url": "https://files.pythonhosted.org/packages/ca/36/ef394c571436b209d3c1994920df6baf1cfac75d3a562e25526a8e809782/django_rest_params-1.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d370d1478c530729d239a7150cf2e2db", "sha256": "1e911192d6bd3008719875d8c7e82dc93eafd434502afe52b1561944e3aa5536" }, "downloads": -1, "filename": "django-rest-params-1.0.2.tar.gz", "has_sig": false, "md5_digest": "d370d1478c530729d239a7150cf2e2db", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6934, "upload_time": "2014-10-19T15:00:54", "url": "https://files.pythonhosted.org/packages/62/20/ba2983442c6bc1088b1ee87b38d1abd5e7a62546b02e980962f32eb86446/django-rest-params-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5f65f75e05933a4957e9fb6f01ca4679", "sha256": "248fe5fcf2e8d24f958d738b33a469b2cbe1f1b0db20082e014abda214f693b8" }, "downloads": -1, "filename": "django_rest_params-1.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5f65f75e05933a4957e9fb6f01ca4679", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12367, "upload_time": "2014-10-19T15:00:57", "url": "https://files.pythonhosted.org/packages/ca/36/ef394c571436b209d3c1994920df6baf1cfac75d3a562e25526a8e809782/django_rest_params-1.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d370d1478c530729d239a7150cf2e2db", "sha256": "1e911192d6bd3008719875d8c7e82dc93eafd434502afe52b1561944e3aa5536" }, "downloads": -1, "filename": "django-rest-params-1.0.2.tar.gz", "has_sig": false, "md5_digest": "d370d1478c530729d239a7150cf2e2db", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6934, "upload_time": "2014-10-19T15:00:54", "url": "https://files.pythonhosted.org/packages/62/20/ba2983442c6bc1088b1ee87b38d1abd5e7a62546b02e980962f32eb86446/django-rest-params-1.0.2.tar.gz" } ] }