Skip to main content

AWS Lambda & API Gateway support for ASGI

Project description

Mangum

Package version Build Status PyPI - Python Version

Mangum is an adapter for using ASGI applications with AWS Lambda & API Gateway. It is intended to provide an easy-to-use, configurable wrapper for any ASGI application deployed in an AWS Lambda function to handle API Gateway requests and responses.

Documentation: https://mangum.io/

Features

  • API Gateway support for HTTP and REST APIs.

  • Compatibility with ASGI application frameworks, such as Starlette, FastAPI, and Quart.

  • Support for binary media types and payload compression in API Gateway using GZip or Brotli.

  • Works with existing deployment and configuration tools, including Serverless Framework and AWS SAM.

  • Startup and shutdown lifespan events.

Requirements

Python 3.6+

Installation

pip install mangum

Example

from mangum import Mangum

async def app(scope, receive, send):
    await send(
        {
            "type": "http.response.start",
            "status": 200,
            "headers": [[b"content-type", b"text/plain; charset=utf-8"]],
        }
    )
    await send({"type": "http.response.body", "body": b"Hello, world!"})


handler = Mangum(app)

Or using a framework.

from fastapi import FastAPI
from mangum import Mangum

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

handler = Mangum(app)

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.11.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

mangum-0.11.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file mangum-0.11.0.tar.gz.

File metadata

  • Download URL: mangum-0.11.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for mangum-0.11.0.tar.gz
Algorithm Hash digest
SHA256 4b8e69030ba2182d4ce089620ee5c5b6075ae3cc5cedb00ab1d3db264231980e
MD5 57a1f5d447940b2bab23691360422690
BLAKE2b-256 a558c94a3b03a1836ed416f912d6e496b33113a09922746e4af67e8e3027bd51

See more details on using hashes here.

Provenance

File details

Details for the file mangum-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: mangum-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for mangum-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 516309ba6d3d62c8fa8371d2779fc41e4f3dc1df91967e83e97db027e56dba1d
MD5 dfdf50731076ab24357697b5c4c5c793
BLAKE2b-256 24720aa38598bfb9a48ca672463d8d2972be85b1671dc41ccec0efdc6755849f

See more details on using hashes here.

Provenance

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