# 🎷 FuncTown 🎷
[![PyPI Version](https://img.shields.io/pypi/v/functown.svg)](https://pypi.python.org/pypi/functown)
[![PyPI downloads](https://img.shields.io/pypi/dm/functown.svg)](https://pypistats.org/packages/functown)
![Packaging](https://github.com/felixnext/python-functown/actions/workflows/python-package.yml/badge.svg)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/functown.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/functown/)
[![Code style: Black](https://img.shields.io/badge/code%20style-Black-000000.svg)](https://github.com/psf/black)
`FuncTown` is a python library that is designed to make your life with Azure Functions
easier.
The core features of `FuncTown` are:
* **Error handling** - automatically handle errors and return a response to the user
* **Debugging** - Set debug flags that automatically return logs and traces as part of
error responses from your function
* **JWT token validation** - automatically validate JWT tokens and provide the user
information
* **Request argument parsing** - automatically parse arguments from the `HttpRequest`
and provide them to your function
* **Metrics** - Handle connections to Application Insights and gives you easy to use
metrics objects
* **Logging, Tracing & Events** - Log your functions data directly into Application
Insights
For detailed features see the [docs](docs/overview.md).
## Getting Started
You can install `FuncTown` using `pip`:
```bash
pip install functown
```
> Note that some dependencies are hidden behind sub-packages (e.g. `functown[jwt]` for
> JWT token validation).
Almost all functionality of `FuncTown` is provided through decorators.
If you want to add error handling to your function:
```python
from logging import Logger
from functown import ErrorHandler
@ErrorHandler(debug=True, enable_logger=True)
def main(req: func.HttpRequest, logger: Logger, **kwargs) -> func.HttpResponse:
logger.info('Python HTTP trigger function processed a request.')
# ...
# exception will be caught and handled by the decorator (returning a 500)
raise ValueError("something went wrong")
return func.HttpResponse("success", status_code=200)
```
> Note: Decorators might pass down additional arguments to your function,
> so it is generally a good idea to modify your function signature to accept these
> arguments (see [docs](docs/overview.md) for more information) and add a `**kwargs`
> to the end.
Decorators are also stackable, so we could parse function arguments and handle a JWT
Token in the same function:
```python
from functown import ArgsHandler, RequestArgHandler, AuthHandler
from functown.auth import Token
@ArgsHandler()
@AuthHandler(scopes=["user.read"])
def main(
req: func.HttpRequest, args: RequestArgHandler, token: Token
) -> func.HttpResponse:
# retrieve some arguments
data = args.get_body_query("data_name", required=True, allowed=["foo", "bar"])
switch = args.get_body("bool_name", map_fct='bool')
file = args.get_file('file_name', required=True)
# check the user id
user_id = token.user_id
# ...
```
This would also directly fail with a `400` message if there is no token provided,
or the token does not contain the required scopes.
Be sure to check out the [docs](docs/overview.md) for a full overview of all
decorators.
If you want to test it on your own Azure Subscription, you can check out the
[example guide](docs/dev-guide.md#setting-up-the-function-app) in the dev section of the
docs.
🎷 Welcome to FuncTown! 🎷
## Note
‼️ If you find this library helpful or have suggestions please let me know.
Also any contributions are welcome! ‼️
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/felixnext)
Raw data
{
"_id": null,
"home_page": "https://github.com/felixnext/python-functown",
"name": "functown",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "azure functions",
"author": "Felix Geilert",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/92/4e/f10e43cea71f78f60fb2b0188c59d2e75b1f6dace68b81718d5d6543ac77/functown-2.3.3.tar.gz",
"platform": null,
"description": "# \ud83c\udfb7 FuncTown \ud83c\udfb7\n\n[![PyPI Version](https://img.shields.io/pypi/v/functown.svg)](https://pypi.python.org/pypi/functown)\n[![PyPI downloads](https://img.shields.io/pypi/dm/functown.svg)](https://pypistats.org/packages/functown)\n![Packaging](https://github.com/felixnext/python-functown/actions/workflows/python-package.yml/badge.svg)\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/functown.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/functown/)\n[![Code style: Black](https://img.shields.io/badge/code%20style-Black-000000.svg)](https://github.com/psf/black)\n\n`FuncTown` is a python library that is designed to make your life with Azure Functions\neasier.\n\nThe core features of `FuncTown` are:\n\n* **Error handling** - automatically handle errors and return a response to the user\n* **Debugging** - Set debug flags that automatically return logs and traces as part of\nerror responses from your function\n* **JWT token validation** - automatically validate JWT tokens and provide the user\ninformation\n* **Request argument parsing** - automatically parse arguments from the `HttpRequest`\nand provide them to your function\n* **Metrics** - Handle connections to Application Insights and gives you easy to use\nmetrics objects\n* **Logging, Tracing & Events** - Log your functions data directly into Application\nInsights\n\nFor detailed features see the [docs](docs/overview.md).\n\n## Getting Started\n\nYou can install `FuncTown` using `pip`:\n\n```bash\npip install functown\n```\n\n> Note that some dependencies are hidden behind sub-packages (e.g. `functown[jwt]` for\n> JWT token validation).\n\nAlmost all functionality of `FuncTown` is provided through decorators.\nIf you want to add error handling to your function:\n\n```python\nfrom logging import Logger\nfrom functown import ErrorHandler\n\n@ErrorHandler(debug=True, enable_logger=True)\ndef main(req: func.HttpRequest, logger: Logger, **kwargs) -> func.HttpResponse:\n logger.info('Python HTTP trigger function processed a request.')\n\n # ...\n # exception will be caught and handled by the decorator (returning a 500)\n raise ValueError(\"something went wrong\")\n\n return func.HttpResponse(\"success\", status_code=200)\n```\n\n> Note: Decorators might pass down additional arguments to your function,\n> so it is generally a good idea to modify your function signature to accept these\n> arguments (see [docs](docs/overview.md) for more information) and add a `**kwargs`\n> to the end.\n\nDecorators are also stackable, so we could parse function arguments and handle a JWT\nToken in the same function:\n\n```python\nfrom functown import ArgsHandler, RequestArgHandler, AuthHandler\nfrom functown.auth import Token\n\n@ArgsHandler()\n@AuthHandler(scopes=[\"user.read\"])\ndef main(\n req: func.HttpRequest, args: RequestArgHandler, token: Token\n) -> func.HttpResponse:\n # retrieve some arguments\n data = args.get_body_query(\"data_name\", required=True, allowed=[\"foo\", \"bar\"])\n switch = args.get_body(\"bool_name\", map_fct='bool')\n file = args.get_file('file_name', required=True)\n\n # check the user id\n user_id = token.user_id\n\n # ...\n```\n\nThis would also directly fail with a `400` message if there is no token provided,\nor the token does not contain the required scopes.\n\nBe sure to check out the [docs](docs/overview.md) for a full overview of all\ndecorators.\n\nIf you want to test it on your own Azure Subscription, you can check out the\n[example guide](docs/dev-guide.md#setting-up-the-function-app) in the dev section of the\ndocs.\n\n\ud83c\udfb7 Welcome to FuncTown! \ud83c\udfb7\n\n## Note\n\n\u203c\ufe0f If you find this library helpful or have suggestions please let me know.\nAlso any contributions are welcome! \u203c\ufe0f\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/felixnext)\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Various Helper Tools to make working with azure functions easier",
"version": "2.3.3",
"project_urls": {
"Download": "https://github.com/felixnext/python-functown/releases/tag/v0.1.0-alpha",
"Homepage": "https://github.com/felixnext/python-functown"
},
"split_keywords": [
"azure",
"functions"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8932a1564f90140589e15e8262677170437dd3d021b523453cbbb89655d03af9",
"md5": "1b86d71bad198b425ac2cf4c32ab158c",
"sha256": "19d01d241f51e6939924808aa08c8dd745a67acafedd424b43420577131bb2eb"
},
"downloads": -1,
"filename": "functown-2.3.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1b86d71bad198b425ac2cf4c32ab158c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 44009,
"upload_time": "2024-09-30T16:07:45",
"upload_time_iso_8601": "2024-09-30T16:07:45.195323Z",
"url": "https://files.pythonhosted.org/packages/89/32/a1564f90140589e15e8262677170437dd3d021b523453cbbb89655d03af9/functown-2.3.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "924ef10e43cea71f78f60fb2b0188c59d2e75b1f6dace68b81718d5d6543ac77",
"md5": "c8289c19479d45086c091c5aecc7bcd5",
"sha256": "63e015e9873830ec3d4820755a857f445594100d456da70372b2a125860a7d7a"
},
"downloads": -1,
"filename": "functown-2.3.3.tar.gz",
"has_sig": false,
"md5_digest": "c8289c19479d45086c091c5aecc7bcd5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 32331,
"upload_time": "2024-09-30T16:07:46",
"upload_time_iso_8601": "2024-09-30T16:07:46.654614Z",
"url": "https://files.pythonhosted.org/packages/92/4e/f10e43cea71f78f60fb2b0188c59d2e75b1f6dace68b81718d5d6543ac77/functown-2.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-30 16:07:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "felixnext",
"github_project": "python-functown",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "azure-functions",
"specs": [
[
">=",
"1.10.1"
]
]
},
{
"name": "requests",
"specs": [
[
">=",
"2.27.1"
]
]
}
],
"lcname": "functown"
}