Skip to main content

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

Metadata

Release files for functown 2.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for functown 2.3.3
File Size Uploaded
functown-2.3.3.tar.gz 32.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for functown 2.3.3
File Interpreter ABI Platform
functown-2.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 76.3 kB

Release files / functown-2.3.3.tar.gz

Download URL functown-2.3.3.tar.gz
Size 32.3 kB
Tags Source
SHA-256 checksum
How to use checksums
63e015e9873830ec3d4820755a857f445594100d456da70372b2a125860a7d7a
BLAKE2b-256 checksum
How to use checksums
924ef10e43cea71f78f60fb2b0188c59d2e75b1f6dace68b81718d5d6543ac77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / functown-2.3.3-py3-none-any.whl

Download URL functown-2.3.3-py3-none-any.whl
Size 44.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
19d01d241f51e6939924808aa08c8dd745a67acafedd424b43420577131bb2eb
BLAKE2b-256 checksum
How to use checksums
8932a1564f90140589e15e8262677170437dd3d021b523453cbbb89655d03af9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release history Release notifications | RSS feed

This release

2.3.3 This release

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page