Skip to main content

ASGI serverless adapters

Project description

Mangum

Serverless response handlers for ASGI applications.

Work in progress

Currently supports AWS Lambda/API Gateway and Azure Functions. Experimental/unstable.

Requirements: Python 3.6+

Installation

pip install mangum

Note: The package on PyPi may be significantly behind the active development, so you probably want to clone the repo instead.

Example

class App:
    def __init__(self, scope) -> None:
        self.scope = scope

    async def __call__(self, receive, send) -> None:
        message = await receive()
        if message["type"] == "http.request":
            await send(
                {
                    "type": "http.response.start",
                    "status": 200,
                    "headers": [[b"content-type", b"text/plain"]],
                }
            )
            await send({"type": "http.response.body", "body": b"Hello, world!"})

AWS Lambda/API Gateway

from mangum.handlers.aws import aws_handler


def lambda_handler(event, context):
    return aws_handler(App, event, context)

Azure Functions

from mangum.handlers.azure import azure_handler
import azure.functions as func

def main(req):
    response = azure_handler(App, req)
    return func.HttpResponse(response["body"], status_code=response["status_code"])

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.2.1.tar.gz (3.2 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