{ "info": { "author": "shivanshs9", "author_email": "shivanshs9@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "DRF Problems [![PyPI version](https://badge.fury.io/py/drf-problems.svg)](https://badge.fury.io/py/drf-problems)\n================\n\n## TL;DR\nThis library implements [RFC 7807](https://tools.ietf.org/html/rfc7807) in our favorite Django REST Framework! Or, in layman terms, it introduces \"Problem Details\" in the HTTP APIs.\n\nTable of Contents\n-----------------\n* [Features](#features)\n* [Pre-Requisites](#pre-requisites)\n* [Installation](#installation)\n* [Usage](#usage)\n * [With exceptions](#with-exceptions)\n * [With permissions](#with-permissions)\n * [With Views](#with-views)\n* [Resources](#resources)\n* [Roadmap](#roadmap)\n* [Contributing](#contributing)\n\n\n## Features\n- Handles exception to return response with Problem Details model.\n- Added permission mixins and base class to store exception to raise by the view on failure of permission.\n- Added view mixin which throws exception of failed permission.\n- These permissions are compatible with composable permissions introduced in DRF 3.9.0!\n- Has problem description endpoint to understand about the problem with the given code.\n- Has sample permissions which checks for minimum API version.\n\n## Pre-Requisites\n- Django >= 2.0 (Tested with 2.2)\n- djangorestframework >= 3.0.0 (Tested with 3.9.0)\n\n## Installation\nInstall the library as you would for any django library.\n\n- Install using pip.\n`pip install drf-problems`\n- Add 'drf_problems' to your **INSTALLED_APPS** setting.\n```python\nINSTALLED_APPS = (\n ...\n 'drf_problems',\n)\n```\n- DRF's default exception handler needs to be replaced. In your `settings.py`, update:\n```python\nREST_FRAMEWORK = {\n ...\n 'EXCEPTION_HANDLER': 'drf_problems.exceptions.exception_handler',\n```\n- To use the problem description url, you need to update your `urls.py`:\n```python\nurlpatterns = [\n ...\n path('', include('drf_problems.urls'))\n]\n```\n\n## Usage\n### With exceptions\nIn your exception class, define `default_code` with the error code string which is used in the type URI.\nTo set custom title, define `title` with the human-readable summary of the problem type.\nTo set description, define `description` with a long paragraph describing the problem.\n\nFinally, make sure to register your exception with `drf_problems.utils.register_exception` function or `drf_problems.utils.register` decorator.\nHere's a sample exception class:\n```python\nfrom drf_problems.utils import register_exception, register\n\n@register # Either use this decorator\nclass InvalidVersionRequestedException(exceptions.NotAcceptable):\n default_code = 'invalid_version'\n title = 'Invalid API version'\n default_detail = 'Provided API version is invalid.')\n description = 'Malformed or unsupported version string is provided with the request.'\n\nregister_exception(InvalidVersionRequestedException) # Or this method directly.\n```\n\n### With permissions\nUse either `drf_problems.permissions.ProblemPermissionMixin` mixin class with your existing permissions, or extend directly from `drf_problems.permissions.BaseProblemPermission`.\nDefine `exception_class` in the permissions to the desired exception class.\nFor flexibility, you can even set exception instance by setting `exception` attribute on the permission object.\n\nHere's a sample permissions class:\n```python\nfrom drf_problems.permissions import BaseProblemPermission\n\nclass MinimumVersionRequiredPermission(BaseProblemPermission):\n exception_class = InvalidVersionRequestedException\n```\n\n### With Views\n**Note**: The permissions wouldn't throw the desired exception from the view, until the view is extended from the `drf_problems.mixins.AllowPermissionWithExceptionViewMixin` mixin. So, remember to update your views too, for which permissions are updated!\n\n## Resources\n- [Official Guide](https://medium.com/@shivanshs9/drf-problems-21f7bb4d4675)\n- [Problem Details for HTTP APIs](https://tools.ietf.org/html/rfc7807)\n- [REST API Error Handling - Problem Details Response](https://blog.restcase.com/rest-api-error-handling-problem-details-response/)\n\n## Roadmap\n- Add tests with some sample views using exceptions and permissions.\n- Document the code better.\n\n## Contributing\nContributions are very welcome, of any kind - whether finding new issues or any ideas for enhancements or a pull request.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/shivanshs9/drf-problems/", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "drf-problems", "package_url": "https://pypi.org/project/drf-problems/", "platform": "", "project_url": "https://pypi.org/project/drf-problems/", "project_urls": { "Homepage": "https://github.com/shivanshs9/drf-problems/" }, "release_url": "https://pypi.org/project/drf-problems/1.0.2/", "requires_dist": [ "Django (>=1.6)", "djangorestframework (>=3.0.0)" ], "requires_python": "", "summary": "Never liked DRF plain old errors? Forget that and accept RFC 7807 - Problem Details!", "version": "1.0.2" }, "last_serial": 5376985, "releases": { "0.9.0": [ { "comment_text": "", "digests": { "md5": "b61ae01b3ef7fe1f0cd9315cf0b5d418", "sha256": "b3d15444bea5d7e263efc19768617e7598b2e8674fa3eb47fdebad077f35c276" }, "downloads": -1, "filename": "drf_problems-0.9.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b61ae01b3ef7fe1f0cd9315cf0b5d418", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7541, "upload_time": "2019-05-26T08:04:43", "url": "https://files.pythonhosted.org/packages/e4/fa/2a19eee8f5fe3eaee6a84717e331728771583dd5a8d0f099573a7f706d5b/drf_problems-0.9.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9ca4639e599335f13f5357dfea122aac", "sha256": "2374c16095560c5c961ded074881fea4704a6d02c4898e1cd159fe41ef1f8708" }, "downloads": -1, "filename": "drf-problems-0.9.0.tar.gz", "has_sig": false, "md5_digest": "9ca4639e599335f13f5357dfea122aac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5147, "upload_time": "2019-05-26T08:04:49", "url": "https://files.pythonhosted.org/packages/ec/52/05048309242fe9e4f8a1d857325e333957fe51cadbd811ca102786bbd155/drf-problems-0.9.0.tar.gz" } ], "0.9.1": [ { "comment_text": "", "digests": { "md5": "afce41c46e0b45e08869072713f6cc39", "sha256": "a156bc27dc6b322c3f1375d332282e9e9fd0f8aa0f551833342b8988f243ea22" }, "downloads": -1, "filename": "drf_problems-0.9.1-py3-none-any.whl", "has_sig": false, "md5_digest": "afce41c46e0b45e08869072713f6cc39", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8887, "upload_time": "2019-06-02T00:40:14", "url": "https://files.pythonhosted.org/packages/a2/39/92d01afe1f24964f29e80eed8851cbd4ad8602d89607e44ceafb0348bd35/drf_problems-0.9.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "994f4ce998ca3073f26743fd1fef72fb", "sha256": "be51d71bba12e21b17c051a247377ad2dbab6ec5a185ab287c4055ff82781e67" }, "downloads": -1, "filename": "drf-problems-0.9.1.tar.gz", "has_sig": false, "md5_digest": "994f4ce998ca3073f26743fd1fef72fb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6399, "upload_time": "2019-06-02T00:40:18", "url": "https://files.pythonhosted.org/packages/52/17/2037c62b5a26eba6cbcbd7b08feec81987c01f05a813d7402f09506f5f65/drf-problems-0.9.1.tar.gz" } ], "0.9.2": [ { "comment_text": "", "digests": { "md5": "7ae60a96e043628bccf8b5bc824fbd00", "sha256": "fa70cb11f838bfe4f9f27c4ba4c97cc4725c46e37d18e6ca4412a5978602f401" }, "downloads": -1, "filename": "drf_problems-0.9.2-py3-none-any.whl", "has_sig": false, "md5_digest": "7ae60a96e043628bccf8b5bc824fbd00", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8917, "upload_time": "2019-06-02T06:20:49", "url": "https://files.pythonhosted.org/packages/79/b0/8275dd4fb25a738f63c373e0eab553954ae606d13d7e73221cf199e966ab/drf_problems-0.9.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d2aa8865328b104a3070540472f6d133", "sha256": "8902b18081e934b62e2a18f7da89512b1692d14f07e4e2d3bb7dae1270ba7350" }, "downloads": -1, "filename": "drf-problems-0.9.2.tar.gz", "has_sig": false, "md5_digest": "d2aa8865328b104a3070540472f6d133", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6415, "upload_time": "2019-06-02T06:20:52", "url": "https://files.pythonhosted.org/packages/c0/5c/71f51a1a1ccd76778f38b90ff10f77b5f4b38db453d31abc4a68812946b4/drf-problems-0.9.2.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "db3690d84ffde9efe2ef66eeb9d9f13f", "sha256": "d56468e36f77b777596cbced532185869a5b2fa8d9519d5b6ef72ed6682d5033" }, "downloads": -1, "filename": "drf_problems-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "db3690d84ffde9efe2ef66eeb9d9f13f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9097, "upload_time": "2019-06-07T21:08:06", "url": "https://files.pythonhosted.org/packages/ec/d8/dd1ba9143ef51ca19424229728d06b27d7aa33d4483b3e2912f518f832a8/drf_problems-1.0.0-py3-none-any.whl" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "6a457946c2493f849e27446bdf278b04", "sha256": "63a4dbb77c375fe4c7787e18755c7df09922d431c5ab622877f61662f24464fa" }, "downloads": -1, "filename": "drf_problems-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "6a457946c2493f849e27446bdf278b04", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9313, "upload_time": "2019-06-09T06:06:55", "url": "https://files.pythonhosted.org/packages/43/14/a60a45830ab0da61819ef0472b139b80971bafff5095f7fc6ff0d16df003/drf_problems-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "14873a3db2ecf80bf74af05b89525c26", "sha256": "31531ede8f3504fb76141bbfb2e9149114115358d530819396896c8804129d4c" }, "downloads": -1, "filename": "drf-problems-1.0.1.tar.gz", "has_sig": false, "md5_digest": "14873a3db2ecf80bf74af05b89525c26", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7451, "upload_time": "2019-06-09T06:06:56", "url": "https://files.pythonhosted.org/packages/f9/c5/0bf6f5cc41c5d620804f67606840ec65f4fee3c0d7dc2f61e63e10dba8d5/drf-problems-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "b46f1324719e71701762a5fde0757641", "sha256": "fee447694e0e0cccc8279d9434180977fc86c8dd20cd14b8212ec27f3e3ed1c3" }, "downloads": -1, "filename": "drf_problems-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "b46f1324719e71701762a5fde0757641", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9313, "upload_time": "2019-06-09T06:45:48", "url": "https://files.pythonhosted.org/packages/5d/01/a4e185e76adfe4a50357ec29eb83d3db6a02ad8d53a99f1c0a450bb25ecc/drf_problems-1.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d4a1ef102ebb2e346bffc8460eb9fd3b", "sha256": "3b3f72073fff4fd524374c6cb74686ca55a8f5b0a00a683a65c66ab5a18fdd3b" }, "downloads": -1, "filename": "drf-problems-1.0.2.tar.gz", "has_sig": false, "md5_digest": "d4a1ef102ebb2e346bffc8460eb9fd3b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7451, "upload_time": "2019-06-09T06:45:51", "url": "https://files.pythonhosted.org/packages/52/59/ee0be9cda3d34d2dd5fd66a7be1151076861ec24766413822e1b880f7d93/drf-problems-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b46f1324719e71701762a5fde0757641", "sha256": "fee447694e0e0cccc8279d9434180977fc86c8dd20cd14b8212ec27f3e3ed1c3" }, "downloads": -1, "filename": "drf_problems-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "b46f1324719e71701762a5fde0757641", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9313, "upload_time": "2019-06-09T06:45:48", "url": "https://files.pythonhosted.org/packages/5d/01/a4e185e76adfe4a50357ec29eb83d3db6a02ad8d53a99f1c0a450bb25ecc/drf_problems-1.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d4a1ef102ebb2e346bffc8460eb9fd3b", "sha256": "3b3f72073fff4fd524374c6cb74686ca55a8f5b0a00a683a65c66ab5a18fdd3b" }, "downloads": -1, "filename": "drf-problems-1.0.2.tar.gz", "has_sig": false, "md5_digest": "d4a1ef102ebb2e346bffc8460eb9fd3b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7451, "upload_time": "2019-06-09T06:45:51", "url": "https://files.pythonhosted.org/packages/52/59/ee0be9cda3d34d2dd5fd66a7be1151076861ec24766413822e1b880f7d93/drf-problems-1.0.2.tar.gz" } ] }