{ "info": { "author": "Scientific Computing - Australian Synchrotron", "author_email": "ascomputing@ansto.gov.au", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Environment :: Web Environment", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7" ], "description": "# Cruet\nCruet is a simple toolkit for building microservices with flask. It works with both, function based and class based views.\n\nIt is built on top of:\n- flask\n- marshmallow\n- webargs\n\n## Example\n```python\nfrom flask import Flask\nfrom marshmallow import fields\nfrom cruet import Cruet, use_args, ApiError, ApiResponse\n\napp = Flask(__name__)\ncruet = Cruet(app)\n\n@app.route('/')\n@use_args({'name': fields.Str(required=True)})\ndef index(args):\n if len(args['name']) < 3:\n raise ApiError('Name has to be at least 3 characters', 400)\n\n return ApiResponse({'msg': 'Hello ' + args['name']})\n\nif __name__ == '__main__':\n app.run()\n\n# curl http://localhost:5000/?name='World'\n# {\"data\": {\"msg\": \"Hello World\"}}\n```\n\n\n## Installation\nCruet is available from PyPi\n```\npip install cruet\n```\n\n## Response\nCruet provides the `ApiResponse` class for building json responses that are formatted consistently across all endpoints.\n\n\n## Error Handling\nCruet provides the `ApiError` exception class for raising an exception and returning a formatted json response with the error message. \n\n\n## Input Validation\nCruet uses the excellent [webargs](https://github.com/marshmallow-code/webargs) library for validating HTTP requests. It integrates the library in a very transparent way, which doesn't change the way webargs is being used and their [documentation](https://webargs.readthedocs.io/en/latest) should be used as the reference.\nCruet only adds its own error handling to webargs and provides convenient decorators for different HTTP request input types. \n\nFor general use, the `use_args` and `use_kwargs` decorators can be used. The example above uses `use_args` to check for a parameter called `name`. The webargs library uses the concept of [locations](https://webargs.readthedocs.io/en/latest/quickstart.html#request-locations) to define where it should look for the HTTP request data.\nCruet provides a few convenient decorators for the most common locations.\n\n### Query\nThe `query` decorator looks for the data as part of the arguments in the URL query string.\n\n```python\nfrom cruet import query\n\n@app.route('/')\n@query({'name': fields.Str(required=True)})\ndef index(args):\n if len(args['name']) < 3:\n raise ApiError('Name has to be at least 3 characters', 400)\n\n return ApiResponse({'msg': 'Hello ' + args[\"name\"]})\n\n# curl http://localhost:5000/?name='World'\n# {\"data\": {\"msg\": \"Hello World\"}}\n``` \n\n### Body\nThe `body` decorator looks for json formatted data in the request body.\n\n```python\nfrom cruet import body\n\n@app.route('/', methods=['POST'])\n@body({'name': fields.Str(required=True)})\ndef index(args):\n if len(args['name']) < 3:\n raise ApiError('Name has to be at least 3 characters', 400)\n\n return ApiResponse({'msg': 'Hello ' + args[\"name\"]})\n\n# curl -d '{\"name\":\"World\"}' -H \"Content-Type: application/json\" -X POST http://localhost:5000\n# {\"data\": {\"msg\": \"Hello World\"}}\n``` \n\n### Form\nThe `form` decorator looks for form-urlencoded data.\n\n```python\nfrom cruet import form\n\n@app.route('/', methods=['POST'])\n@form({'name': fields.Str(required=True)})\ndef index(args):\n if len(args['name']) < 3:\n raise ApiError('Name has to be at least 3 characters', 400)\n\n return ApiResponse({'msg': 'Hello ' + args[\"name\"]})\n\n# curl -d \"name=World\" -X POST http://localhost:5000\n# {\"data\": {\"msg\": \"Hello World\"}}\n``` \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/AustralianSynchrotron/cruet", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "cruet", "package_url": "https://pypi.org/project/cruet/", "platform": "", "project_url": "https://pypi.org/project/cruet/", "project_urls": { "Homepage": "https://github.com/AustralianSynchrotron/cruet" }, "release_url": "https://pypi.org/project/cruet/0.0.3/", "requires_dist": [ "Flask (>=1.1.1)", "marshmallow (>=3.0.3)", "webargs (>=5.4.0)", "apispec (>=2.0.2)", "PyYAML (>=5.1.2)" ], "requires_python": "", "summary": "A simple toolkit for building microservices with flask", "version": "0.0.3" }, "last_serial": 5817862, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d756bd34f62c790337eef402a6ac06c3", "sha256": "ab90e4158a84f11d3361464e4b525abf10af79551ee1f18a923d059b6bddc41a" }, "downloads": -1, "filename": "cruet-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d756bd34f62c790337eef402a6ac06c3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 2400, "upload_time": "2019-05-22T06:57:20", "url": "https://files.pythonhosted.org/packages/65/6a/f05a0f434e665606195472c58d5433e2d7ff9e7b8c45cba730462dceddf4/cruet-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3a083a88138dd87e875800eedf25ecdc", "sha256": "3d8b65c0782a1eb31e0bf0738acb95010ae6af039a715b770fa43ab58b364b09" }, "downloads": -1, "filename": "cruet-0.0.1.tar.gz", "has_sig": false, "md5_digest": "3a083a88138dd87e875800eedf25ecdc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1249, "upload_time": "2019-05-22T06:57:22", "url": "https://files.pythonhosted.org/packages/83/d3/389855723aa268cf423113577b76f31d6b3bf58792ab65dc396011df3544/cruet-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "190eca683079b98ba3af10c2642bf4eb", "sha256": "1bbe7c65b2979dc2e09781896e3b01cc97c2d8b83d24c9e385fce26fdc8e2171" }, "downloads": -1, "filename": "cruet-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "190eca683079b98ba3af10c2642bf4eb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5187, "upload_time": "2019-05-27T05:03:16", "url": "https://files.pythonhosted.org/packages/fe/49/80275a85e9eab7633b071c161536687fa9083025158159778b2bb8131636/cruet-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "52ac9123b3ca92c6a21b9eefb8d1649e", "sha256": "53f7b157fbf246e968816bdb91f224c2f15d3a99deb17ca6d5c5a6fe681e104b" }, "downloads": -1, "filename": "cruet-0.0.2.tar.gz", "has_sig": false, "md5_digest": "52ac9123b3ca92c6a21b9eefb8d1649e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2951, "upload_time": "2019-05-27T05:03:17", "url": "https://files.pythonhosted.org/packages/7d/27/77f406670fcc34327d26cea2391787e51bf1434578689cadde857f30a48f/cruet-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "533b28e22c0fd5668524cdc0c19f1dfe", "sha256": "f2310011e3541dd35fcaac9ed3097f812f7e882a2c1383c6672e80951ba139b4" }, "downloads": -1, "filename": "cruet-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "533b28e22c0fd5668524cdc0c19f1dfe", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7252, "upload_time": "2019-09-12T02:33:31", "url": "https://files.pythonhosted.org/packages/0e/2a/3b99b05f67ae3c67688491fab4bd27d3064b4672b00d8b216656ac4f59d7/cruet-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d4c9a67f2e352310e009161101c61441", "sha256": "553ef0dfc0ef2f0e8f84b04c142deb89fa8bd5df1ac4368031a959dc20fa4d2c" }, "downloads": -1, "filename": "cruet-0.0.3.tar.gz", "has_sig": false, "md5_digest": "d4c9a67f2e352310e009161101c61441", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4253, "upload_time": "2019-09-12T02:33:34", "url": "https://files.pythonhosted.org/packages/d3/1d/e4e3d16a1cd1bb7e5c7a3973f271460854f7e6d7323c42306e2173ad5d3e/cruet-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "533b28e22c0fd5668524cdc0c19f1dfe", "sha256": "f2310011e3541dd35fcaac9ed3097f812f7e882a2c1383c6672e80951ba139b4" }, "downloads": -1, "filename": "cruet-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "533b28e22c0fd5668524cdc0c19f1dfe", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7252, "upload_time": "2019-09-12T02:33:31", "url": "https://files.pythonhosted.org/packages/0e/2a/3b99b05f67ae3c67688491fab4bd27d3064b4672b00d8b216656ac4f59d7/cruet-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d4c9a67f2e352310e009161101c61441", "sha256": "553ef0dfc0ef2f0e8f84b04c142deb89fa8bd5df1ac4368031a959dc20fa4d2c" }, "downloads": -1, "filename": "cruet-0.0.3.tar.gz", "has_sig": false, "md5_digest": "d4c9a67f2e352310e009161101c61441", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4253, "upload_time": "2019-09-12T02:33:34", "url": "https://files.pythonhosted.org/packages/d3/1d/e4e3d16a1cd1bb7e5c7a3973f271460854f7e6d7323c42306e2173ad5d3e/cruet-0.0.3.tar.gz" } ] }