{ "info": { "author": "Endurant Devs", "author_email": "info@endurantdevs.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Internet :: WWW/HTTP :: WSGI :: Application" ], "description": "# webargs-sanic\n[Sanic](https://github.com/huge-success/sanic) integration with [Webargs](https://github.com/sloria/webargs). Parsing and validating request arguments: headers, arguments, cookies, files, json, etc.\n\n[![Build Status](https://img.shields.io/travis/EndurantDevs/webargs-sanic.svg?logo=travis)](https://travis-ci.org/EndurantDevs/webargs-sanic) [![Latest Version](https://img.shields.io/pypi/v/webargs-sanic.svg)](https://pypi.python.org/pypi/webargs-sanic/) [![Python Versions](https://img.shields.io/pypi/pyversions/webargs-sanic.svg)](https://github.com/EndurantDevs/webargs-sanic/blob/master/setup.py) [![Tests Coverage](https://img.shields.io/codecov/c/github/EndurantDevs/webargs-sanic/master.svg)](https://codecov.io/gh/EndurantDevs/webargs-sanic)\n\n[webargs](https://github.com/sloria/webargs) is a Python library for parsing and validating HTTP request arguments, with built-in support for popular web frameworks. webargs-sanic allows you to use it for [Sanic](https://github.com/huge-success/sanic) apps. To read more about webargs usage, please check [Quickstart](https://webargs.readthedocs.io/en/latest/quickstart.html)\n\n## Example Code ##\n\n### Simple Application ###\n```python\nfrom sanic import Sanic\nfrom sanic.response import text\n\nfrom webargs import fields\nfrom webargs_sanic.sanicparser import use_args\n\n\napp = Sanic(__name__)\n\nhello_args = {\n 'name': fields.Str(required=True)\n}\n\n@app.route('/')\n@use_args(hello_args)\nasync def index(args):\n return text('Hello ' + args['name'])\n\n\n```\n\n### Class-based Sanic app and args/kwargs ###\n\n```python\nfrom sanic import Sanic\nfrom sanic.views import HTTPMethodView\nfrom sanic.response import json\n\nfrom webargs import fields\nfrom webargs_sanic.sanicparser import use_args, use_kwargs\n\n\napp = Sanic(__name__)\n\nclass EchoMethodViewUseArgs(HTTPMethodView):\n @use_args({\"val\": fields.Int()})\n async def post(self, request, args):\n return json(args)\n\n\napp.add_route(EchoMethodViewUseArgs.as_view(), \"/echo_method_view_use_args\")\n\n\nclass EchoMethodViewUseKwargs(HTTPMethodView):\n @use_kwargs({\"val\": fields.Int()})\n async def post(self, request, val):\n return json({\"val\": val})\n\n\napp.add_route(EchoMethodViewUseKwargs.as_view(), \"/echo_method_view_use_kwargs\")\n```\n\n### Parser without decorator with returning errors as JSON ###\n```python\nfrom sanic import Sanic\nfrom sanic.response import json\n\nfrom webargs import fields\nfrom webargs_sanic.sanicparser import parser, HandleValidationError\n\napp = Sanic(__name__)\n\n@app.route(\"/echo_view_args_validated/\", methods=[\"GET\"])\nasync def echo_use_args_validated(request, args):\n parsed = await parser.parse(\n {\"value\": fields.Int(required=True, validate=lambda args: args[\"value\"] > 42)}, request, locations=(\"view_args\",)\n )\n return json(parsed)\n\n\n# Return validation errors as JSON\n@app.exception(HandleValidationError)\nasync def handle_validation_error(request, err):\n return json({\"errors\": err.exc.messages}, status=422)\n```\n\n### More complicated custom example ###\n```python\nfrom sanic import Sanic\nfrom sanic import response\nfrom sanic import Blueprint\n\nfrom webargs_sanic.sanicparser import use_kwargs\n\nfrom some_CUSTOM_storage import InMemory\n\nfrom webargs import fields\nfrom webargs import validate\n\nimport marshmallow.fields\nfrom validate_email import validate_email\n\n#usually this should not be here, better to import ;)\n#please check examples for more info\nclass Email(marshmallow.fields.Field):\n\n def __init__(self, *args, **kwargs):\n super(Email, self).__init__(*args, **kwargs)\n\n def _deserialize(self, value, attr, obj):\n value = value.strip().lower()\n if not validate_email(value):\n self.fail('validator_failed')\n return value\n\nuser_update = {\n 'user_data': fields.Nested({\n 'email': Email(),\n 'password': fields.Str(validate=lambda value: len(value)>=8),\n 'first_name': fields.Str(validate=lambda value: len(value)>=1),\n 'last_name': fields.Str(validate=lambda value: len(value)>=1),\n 'middle_name': fields.Str(),\n 'gender': fields.Str(validate=validate.OneOf([\"M\", \"F\"])),\n 'birth_date': fields.Date(),\n }),\n 'user_id': fields.Str(required=True, validate=lambda x:len(x)==32),\n}\n\n\nblueprint = Blueprint('app')\nstorage = InMemory()\n\n\n@blueprint.put('/user/')\n@use_kwargs(user_update)\nasync def update_user(request, user_id, user_data):\n storage.update_or_404(user_id, user_data)\n return response.text('', status=204)\n\napp = Sanic(__name__)\napp.blueprint(blueprint, url_prefix='/')\n\n```\n\nFor more examples and checking how to use custom validations (phones, emails, etc.) please check apps in [Examples](https://github.com/EndurantDevs/webargs-sanic/tree/master/examples/)\n\n## Installing ##\n\nIt is easy to do from `pip`\n\n```\npip install webargs-sanic\n```\n\nor from sources\n\n```\ngit clone git@github.com:EndurantDevs/webtest-sanic.git\ncd webtest-sanic\npython setup.py install\n```\n\n## Running the tests\n\nProject uses common tests from webargs package. Thanks to [Steven Loria](https://github.com/sloria) for [sharing tests in webargs v4.1.0](https://github.com/sloria/webargs/pull/287#issuecomment-422232384). \nMost of tests are run by webtest via [webtest-sanic](https://github.com/EndurantDevs/webtest-sanic). \nSome own tests get run via Sanic's TestClient.\n\nTo be sure everything is fine before installation from sources, just run:\n```bash\npip -r requirements.txt\n```\nand then\n```bash\npython setup.py test\n```\nOr\n```bash\npytest tests/\n```\n\n\n## Authors\n[\"Endurant](https://www.endurantdevs.com/)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n\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/EndurantDevs/webargs-sanic", "keywords": "webargs-sanic webargs sanic testing", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "webargs-sanic", "package_url": "https://pypi.org/project/webargs-sanic/", "platform": "", "project_url": "https://pypi.org/project/webargs-sanic/", "project_urls": { "Homepage": "https://github.com/EndurantDevs/webargs-sanic" }, "release_url": "https://pypi.org/project/webargs-sanic/1.5.0/", "requires_dist": [ "sanic (>=0.8.3)", "webargs (>=5.1.3)" ], "requires_python": "", "summary": "webargs-sanic provides integration of Webargs with Sanic applications", "version": "1.5.0" }, "last_serial": 5614888, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "eecdd562016bbb57cb7577655f50cd12", "sha256": "eb16e6fac5d66ee45961825ad65f505c0fa6cbc1a73a320b4c1355c9f5fd1a7e" }, "downloads": -1, "filename": "webargs-sanic-0.0.1.tar.gz", "has_sig": false, "md5_digest": "eecdd562016bbb57cb7577655f50cd12", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1540, "upload_time": "2018-09-17T12:47:01", "url": "https://files.pythonhosted.org/packages/5e/eb/b834328495e7f89f177361f680616a68aee672e71b8c004b26b315cbda22/webargs-sanic-0.0.1.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "689de6bd705ba3a76603c1ade0d69bcf", "sha256": "0f37649ef76bbf70f96b8090d8c09387387d21e7797f27ba6e3ac2d61194397b" }, "downloads": -1, "filename": "webargs-sanic-0.0.5.tar.gz", "has_sig": false, "md5_digest": "689de6bd705ba3a76603c1ade0d69bcf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2691, "upload_time": "2018-09-17T13:29:18", "url": "https://files.pythonhosted.org/packages/8f/d6/88d7cd2bc1a5b13bc376643b0bd7997e5ada8f3e3ea4ee521d2cf85c10d0/webargs-sanic-0.0.5.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "7f71e2577fc0e64997e1cd4746ea31ad", "sha256": "14aa3d389d3671d0bb05f6a6b14af050d8cd07702d9acf512fa0483ac9f403be" }, "downloads": -1, "filename": "webargs-sanic-0.0.7.tar.gz", "has_sig": false, "md5_digest": "7f71e2577fc0e64997e1cd4746ea31ad", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2689, "upload_time": "2018-09-17T15:50:03", "url": "https://files.pythonhosted.org/packages/60/55/2a7222c4c1b393557e03546c4563b0aa15ec5282ab5e645e9fff2c74ba4d/webargs-sanic-0.0.7.tar.gz" } ], "0.0.8": [ { "comment_text": "", "digests": { "md5": "a9e39c57f147a6f0c2618d3566ee9370", "sha256": "0bf214af4c0e3e321acc2bcaaee78f78ffa9c305ec4bd48673b7d45798e0559f" }, "downloads": -1, "filename": "webargs-sanic-0.0.8.tar.gz", "has_sig": false, "md5_digest": "a9e39c57f147a6f0c2618d3566ee9370", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2697, "upload_time": "2018-09-17T15:59:19", "url": "https://files.pythonhosted.org/packages/22/78/6132d3cb29d9f48f78f5d930c35f870be16f78b51d643d20bb490f3e1884/webargs-sanic-0.0.8.tar.gz" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "ed76c3b353198f9d69335bd131cbdabe", "sha256": "e949306e53e1269a097b2f983af0dea0bb1394efcfe4513a8efa2843c8a1cdde" }, "downloads": -1, "filename": "webargs-sanic-0.0.9.tar.gz", "has_sig": false, "md5_digest": "ed76c3b353198f9d69335bd131cbdabe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2965, "upload_time": "2018-09-17T16:23:59", "url": "https://files.pythonhosted.org/packages/78/dd/4a818de21c177a4157ee49da0e7cbb4d11e7eec49596bc23cb1e63d73d73/webargs-sanic-0.0.9.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "0332b5b6094a0e209f1a6325f2e7308a", "sha256": "c3a72b40e7768f3456879dac60564861e083923b60f5f3ebf5362d011dc5d80e" }, "downloads": -1, "filename": "webargs_sanic-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0332b5b6094a0e209f1a6325f2e7308a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3593, "upload_time": "2018-09-18T09:41:29", "url": "https://files.pythonhosted.org/packages/b3/92/ba9a4c6bae9d7bb19f22c6c7d1bb40422d97625e5154893cf610abad42aa/webargs_sanic-0.1.0-py3-none-any.whl" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "21dc3d21da44785a38b1523c3c87e123", "sha256": "8121a948d4e699075da3fd9584076c34ab79e6e586e295553eb2ac9cb8a1afdf" }, "downloads": -1, "filename": "webargs_sanic-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "21dc3d21da44785a38b1523c3c87e123", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3591, "upload_time": "2018-09-18T16:15:05", "url": "https://files.pythonhosted.org/packages/01/7b/5945bfbd577dd0acaaed59b9573e0dfdc28958d3ce1ed31f4837fccd3271/webargs_sanic-0.1.1-py3-none-any.whl" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "712acf484285317a8aa1aaa4cbcc113d", "sha256": "1ff5c5d8d4f5093dfbf9259e1b2cd562f8c21e87b7eb61e834394ac64b875f25" }, "downloads": -1, "filename": "webargs_sanic-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "712acf484285317a8aa1aaa4cbcc113d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4441, "upload_time": "2018-09-18T16:55:38", "url": "https://files.pythonhosted.org/packages/0b/85/dcbf8bf5a412716484808ba9d503f5433f8be8cc1efe06ca8d08772baaee/webargs_sanic-1.0.1-py3-none-any.whl" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "3c31505a7726235df2ef5aa08e166d85", "sha256": "c5e49797c40dcb3098f13fab84daa658d525b42547de8b6ad1363cb866367d95" }, "downloads": -1, "filename": "webargs_sanic-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "3c31505a7726235df2ef5aa08e166d85", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4467, "upload_time": "2018-09-18T17:39:48", "url": "https://files.pythonhosted.org/packages/44/ff/fea0e843caff1f9aabe36e4d397b6982a8d478769530de055544c009fcbc/webargs_sanic-1.0.2-py3-none-any.whl" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "2f8beb0465ca7c1449f3e165deccd287", "sha256": "25ef09f767a15be85bfe3e17a64fb526caa1093641190509d9566ceade4c785c" }, "downloads": -1, "filename": "webargs_sanic-1.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "2f8beb0465ca7c1449f3e165deccd287", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4987, "upload_time": "2018-09-19T19:47:03", "url": "https://files.pythonhosted.org/packages/09/42/b8b5aced80f8fb7ace4474957f16f4a60aa901f97763a29c3580713963df/webargs_sanic-1.0.3-py3-none-any.whl" } ], "1.5.0": [ { "comment_text": "", "digests": { "md5": "c3431825e8967f3120683b27f811b556", "sha256": "6d360318cde5c6205ff3396cd77716bce1453e91acc621db38c368b4f883eedc" }, "downloads": -1, "filename": "webargs_sanic-1.5.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c3431825e8967f3120683b27f811b556", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6023, "upload_time": "2019-07-31T18:25:28", "url": "https://files.pythonhosted.org/packages/2d/84/6804760fee668acb31f412b1d9ae41db79867cd1c64f6bf5cadad3489d99/webargs_sanic-1.5.0-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c3431825e8967f3120683b27f811b556", "sha256": "6d360318cde5c6205ff3396cd77716bce1453e91acc621db38c368b4f883eedc" }, "downloads": -1, "filename": "webargs_sanic-1.5.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c3431825e8967f3120683b27f811b556", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6023, "upload_time": "2019-07-31T18:25:28", "url": "https://files.pythonhosted.org/packages/2d/84/6804760fee668acb31f412b1d9ae41db79867cd1c64f6bf5cadad3489d99/webargs_sanic-1.5.0-py3-none-any.whl" } ] }