Skip to main content

ASGI serverless adapters

Project description

Mangum

Documentation: https://erm.github.io/mangum/

Package version Build Status

Mangum is a library for using ASGI applications with FaaS platforms.

Requirements

Python 3.6+

Installation

$ pip3 install mangum

Dependencies

There are required/optional dependencies for specific platforms being used, but the base install does not have any hard requirements:

azure-functions - required for Azure Function support. Can be installed using:

$ pip3 install mangum[azure]

boto3, click - required for the AWS-specific CLI tools (this is NOT required in deployments):

$ pip3 install mangum[aws]

Everything can be installed with:

$ pip3 install mangum[full]

Supported Platforms

Only two platforms are currently supported, but if you'd like to see others, please open an issue.

AWS Lambda / API Gateway

To make an ASGI application compatible with AWS Lambda & AWS Gateway, wrap it in the AWSLambdaMiddleware:

# asgi.py

from mangum.platforms.aws.middleware import AWSLambdaMiddleware
from yourapp.app import app


handler = AWSLambdaMiddleware(app)  # optionally set debug=True

For this example, you would need to specify your lambda event handler as asgi.handler.

Note: This platform middleware can also use an optional debug argument to return unhandled errors raised by the application. It should NOT be enabled outside of development.

Azure Functions

Similarly as above, wrap the application using the AzureFunctionMiddleware:

from mangum.platforms.azure.middleware import AzureFunctionMiddleware
from yourapp.app import app

handler = AzureFunctionMiddleware(app)

A basic quickstart guide for using Azure Functions with Mangum is outlined here.

Mangum CLI (experimental)

Experimental AWS packaging/deployment support. This requires installation of the optional dependencies for AWS:

$ pip install mangum[full]

It also requires:

  • AWS CLI
  • AWS credentials.

The available commands are briefly outlined below, but there is also a quickstart guide here:

  • mangum aws init - Create a new configuration template for an application.

  • mangum aws build - Install the requirements and copy the application files into the build directory.

  • mangum aws package - Package the local project to prepare for deployment.

  • mangum aws deploy - Deploy the packaged application to AWS.

  • mangum aws tail - Tail the last 10 minutes of CloudWatch for the function.

  • mangum aws describe - Retrieve the API endpoints for the function.

  • mangum aws validate - Validate the SAM template in the current configuration.

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

mangum-0.5.8.tar.gz (11.3 kB view hashes)

Uploaded Source

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