Skip to main content

Various Helper Tools to make working with azure functions easier

Project description

🎷 FuncTown 🎷

PyPI Version PyPI downloads Packaging Supported Python versions Code style: 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.

Getting Started

You can install FuncTown using pip:

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:

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 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:

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 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 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"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

functown-2.1.1.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

functown-2.1.1-py3-none-any.whl (41.0 kB view details)

Uploaded Python 3

File details

Details for the file functown-2.1.1.tar.gz.

File metadata

  • Download URL: functown-2.1.1.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for functown-2.1.1.tar.gz
Algorithm Hash digest
SHA256 4c731bc5923d84ac87fd2e62765c2e5b845c592f7cbc60994421d8a763809323
MD5 1438a9eb61870cad30b6b21f1be138c6
BLAKE2b-256 9cb037376943c04bdf6e6796a2a9e98445de44583c417aad3812a73551295d7e

See more details on using hashes here.

File details

Details for the file functown-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: functown-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 41.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for functown-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68106a96b85c732142f014345bf33f770bc85dfa5f8aacccd901780cbe3fc1bf
MD5 539cd3bfd217d0a1db87de404f0c0374
BLAKE2b-256 92fad18a4e658f20273046a54aeb16cdb92d02f2ce127fa5451e0c20476c0053

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page