{"id":19869674,"url":"https://github.com/eduardomourar/python-functionapprest","last_synced_at":"2025-05-02T08:30:56.003Z","repository":{"id":52703406,"uuid":"171884568","full_name":"eduardomourar/python-functionapprest","owner":"eduardomourar","description":"Python micro web framework for Azure Functions","archived":false,"fork":false,"pushed_at":"2023-02-02T06:30:11.000Z","size":41,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T03:03:20.395Z","etag":null,"topics":["azure-functions","framework","json-schema","python","routing"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/functionapprest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eduardomourar.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-21T14:16:14.000Z","updated_at":"2023-03-14T12:53:28.000Z","dependencies_parsed_at":"2023-02-17T15:15:30.018Z","dependency_job_id":null,"html_url":"https://github.com/eduardomourar/python-functionapprest","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eduardomourar%2Fpython-functionapprest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eduardomourar%2Fpython-functionapprest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eduardomourar%2Fpython-functionapprest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eduardomourar%2Fpython-functionapprest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eduardomourar","download_url":"https://codeload.github.com/eduardomourar/python-functionapprest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250457796,"owners_count":21433735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure-functions","framework","json-schema","python","routing"],"created_at":"2024-11-12T16:06:28.668Z","updated_at":"2025-05-02T08:30:55.680Z","avatar_url":"https://github.com/eduardomourar.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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/\u003cint:id\u003e/')\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/\u003cpath:path\u003e')\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/\u003cpath:product_id\u003e/')\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\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feduardomourar%2Fpython-functionapprest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feduardomourar%2Fpython-functionapprest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feduardomourar%2Fpython-functionapprest/lists"}