Skip to main content

ASGI serverless adapters

Project description

Mangum

Package version Build Status

Mangum is a library for adapting ASGI applications to use on FaaS platforms.

Important: This project is under active development and in an experimental/unstable state.

Supported Platforms

  • AWS Lambda + API Gateway
  • Azure Functions

Requirements

Python 3.6+

Installation

pip3 install mangum

Example

Below is a basic ASGI application example that can be used with handler methods:

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 asgi_handler(event, context):
    return aws_handler(App, event, context)

Azure Functions

from mangum.handlers.azure import azure_handler

def asgi_handler(req):
    return azure_handler(App, req)

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.6.tar.gz (3.7 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