{ "info": { "author": "eduardomourar", "author_email": "eduardo_demoura@yahoo.com.br", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "Natural Language :: English", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# functionapprest\n\n[![Build Status](https://travis-ci.com/eduardomourar/python-functionapprest.svg?branch=master)](https://travis-ci.com/eduardomourar/python-functionapprest) [![Latest Version](https://img.shields.io/pypi/v/functionapprest.svg)](https://pypi.python.org/pypi/functionapprest) [![Python Support](https://img.shields.io/pypi/pyversions/functionapprest.svg)](https://pypi.python.org/pypi/functionapprest)\n\nPython routing mini-framework for [MS Azure Functions](https://azure.microsoft.com/en-us/services/functions/) with optional JSON-schema validation.\n\n** This repository is based heavily on [lambdarest project](https://github.com/trustpilot/python-lambdarest)\n\n### Features\n\n* `functionapp_handler` function constructor with built-in dispatcher\n* Decorator to register functions to handle HTTP methods\n* Optional JSON-schema input validation using same decorator\n\n## Installation\n\nInstall the package from [PyPI](http://pypi.python.org/pypi/) using [pip](https://pip.pypa.io/):\n\n```bash\npip install functionapprest\n```\n\n## Getting Started\n\nThis module helps you to handle different HTTP methods in your Azure Functions.\n\n```python\nfrom functionapprest import functionapp_handler\n\n@functionapp_handler.handle('get')\ndef my_own_get(event):\n return {'this': 'will be json dumped'}\n```\n\n## Advanced Usage\n\nOptionally you can validate an incoming JSON body against a JSON schema:\n\n```python\nmy_schema = {\n '$schema': 'http://json-schema.org/draft-04/schema#',\n 'type': 'object',\n 'properties': {\n 'body':{\n 'type': 'object',\n 'properties': {\n 'foo': {\n 'type': 'string'\n }\n }\n }\n }\n}\n\n@functionapp_handler.handle('get', path='/with-schema/', schema=my_schema)\ndef my_own_get(event):\n return {'this': 'will be json dumped'}\n```\n\n### Query Params\n\nQuery params are also analyzed and validate with JSON schemas.\nQuery arrays are expected to be comma separated, all numbers are converted to floats.\n\n```python\nmy_schema = {\n '$schema': 'http://json-schema.org/draft-04/schema#',\n 'type': 'object',\n 'properties': {\n 'query':{\n 'type': 'object',\n 'properties': {\n 'foo': {\n 'type': 'array',\n 'items': {\n 'type': 'number'\n }\n }\n }\n }\n }\n}\n\n@functionapp_handler.handle('get', path='/with-params/', schema=my_schema)\ndef my_own_get(event):\n return event.json['query']\n\n```\n\n### Routing\n\nYou can also specify which path to react on for individual handlers using the `path` param:\n\n```python\n@functionapp_handler.handle('get', path='/foo/bar/baz')\ndef my_own_get(event):\n return {'this': 'will be json dumped'}\n```\n\nAnd you can specify path parameters as well, which will be passed as keyword arguments:\n\n```python\n@functionapp_handler.handle('get', path='/foo//')\ndef my_own_get(event, id):\n return {'my-id': id}\n```\n\nOr use the proxy endpoint:\n```python\n@functionapp_handler.handle('get', path='/bar/')\ndef my_own_get(event, path):\n return {'path': path}\n```\n\n## Using within Function App\n\n**function.json**\n\n```json\n{\n \"scriptFile\": \"handler.py\",\n \"bindings\": [\n {\n \"authLevel\": \"anonymous\",\n \"type\": \"httpTrigger\",\n \"direction\": \"in\",\n \"name\": \"req\",\n \"methods\": [\n \"get\"\n ],\n \"route\": \"products/{product_id}\"\n },\n {\n \"type\": \"http\",\n \"direction\": \"out\",\n \"name\": \"$return\"\n }\n ]\n}\n```\n\n**handler.py**\n\n```python\nfrom functionapprest import functionapp_handler, Request\n\n@functionapp_handler.handle('get', path='/products//')\ndef list_products(req: Request, product_id):\n query = req.json.get('query', {})\n body = req.json.get('body', {})\n headers = req.get('headers', {})\n params = req.get('params', {})\n response = {\n 'method': req.method,\n 'url': req.url,\n 'headers': headers,\n 'params': params,\n 'query': query,\n 'body': body\n }\n return response\n\nmain = functionapp_handler\n```\n\n## Tests\n\nYou can use pytest to run tests against your current Python version. To run tests for current python version run `pytest`\n\n\nSee [`setup.py`](setup.py) for test dependencies and install them with `pipenv install --dev`.\n\n## Contributors\neduardomourar", "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/eduardomourar/python-functionapprest", "keywords": "functionapp azure rest json schema jsonschema", "license": "", "maintainer": "", "maintainer_email": "", "name": "functionapprest", "package_url": "https://pypi.org/project/functionapprest/", "platform": "", "project_url": "https://pypi.org/project/functionapprest/", "project_urls": { "Homepage": "https://github.com/eduardomourar/python-functionapprest" }, "release_url": "https://pypi.org/project/functionapprest/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "Micro framework for azure functions with optional json schema validation", "version": "0.2.0" }, "last_serial": 5329480, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "503dc4246796715d8027f4a82510fa0a", "sha256": "6cdf38b738cd382ea2d41a4077820401d6f4f2588510821f708c31d6373f4131" }, "downloads": -1, "filename": "functionapprest-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "503dc4246796715d8027f4a82510fa0a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7649, "upload_time": "2019-02-21T20:40:10", "url": "https://files.pythonhosted.org/packages/9b/bd/fb2fc161e062a58c8a34f1d08359e126bf8fa74e815883b5881afe09413e/functionapprest-0.0.1-py2.py3-none-any.whl" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "367125b722e60381699f475ba8b0b7a8", "sha256": "44a4071378f338a74d4828e36d2c83a963a201ed3fd2a320c77a43dea42587d9" }, "downloads": -1, "filename": "functionapprest-0.1.0.tar.gz", "has_sig": false, "md5_digest": "367125b722e60381699f475ba8b0b7a8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8911, "upload_time": "2019-02-22T17:14:56", "url": "https://files.pythonhosted.org/packages/70/01/b27fc9a3e458fe40f11f415dee726cdb1c86e07827807aeaab6d98a025d5/functionapprest-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "aa2b00a351cb21a077d25c288a55c560", "sha256": "fd288f993946a89e1f25ad40b17a3b40ca16f7d05a8e99930e44bcbe89da4e9e" }, "downloads": -1, "filename": "functionapprest-0.1.1.tar.gz", "has_sig": false, "md5_digest": "aa2b00a351cb21a077d25c288a55c560", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9398, "upload_time": "2019-02-27T00:28:56", "url": "https://files.pythonhosted.org/packages/76/f3/da34289157f83e144f7152c0d4d9bf3c5133fa8bcb4cda18121e704a912a/functionapprest-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "c3b87848374f05a7ede5feb968e2011f", "sha256": "6a2f1ce221594a7af17c758726f00001355adc9f6ea6e1ddbd50f92c9175b113" }, "downloads": -1, "filename": "functionapprest-0.1.2.tar.gz", "has_sig": false, "md5_digest": "c3b87848374f05a7ede5feb968e2011f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9503, "upload_time": "2019-02-28T00:43:25", "url": "https://files.pythonhosted.org/packages/f0/66/84916e078a6b9f867fc46065a3ef0865b185f068d960019723e062c1472e/functionapprest-0.1.2.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "17176077dc5ec79f3a494f9573b4f78b", "sha256": "67133dd34a248cb23afa4dc8fd5b690ae021810b23f3b02c2fc1d93c1618086a" }, "downloads": -1, "filename": "functionapprest-0.2.0.tar.gz", "has_sig": false, "md5_digest": "17176077dc5ec79f3a494f9573b4f78b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9890, "upload_time": "2019-05-28T23:17:49", "url": "https://files.pythonhosted.org/packages/af/20/3ffd89d5145dc11e0950062824cefd823ff826e90d05a025764819a96604/functionapprest-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "17176077dc5ec79f3a494f9573b4f78b", "sha256": "67133dd34a248cb23afa4dc8fd5b690ae021810b23f3b02c2fc1d93c1618086a" }, "downloads": -1, "filename": "functionapprest-0.2.0.tar.gz", "has_sig": false, "md5_digest": "17176077dc5ec79f3a494f9573b4f78b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9890, "upload_time": "2019-05-28T23:17:49", "url": "https://files.pythonhosted.org/packages/af/20/3ffd89d5145dc11e0950062824cefd823ff826e90d05a025764819a96604/functionapprest-0.2.0.tar.gz" } ] }