AWS Lambda support for ASGI applications
Project description
Mangum
Mangum is an adapter for running ASGI applications in AWS Lambda to handle Function URL, API Gateway, ALB, and Lambda@Edge events.
Documentation: https://mangum.fastapiexpert.com/
Features
-
Event handlers for API Gateway HTTP and REST APIs, Application Load Balancer, Function URLs, and CloudFront Lambda@Edge.
-
Compatibility with ASGI application frameworks, such as Starlette, FastAPI, Quart and Django.
-
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.
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, lifespan="off")
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, lifespan="off")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mangum-0.18.0.tar.gz
.
File metadata
- Download URL: mangum-0.18.0.tar.gz
- Upload date:
- Size: 86.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50179395012d9ae3df30484c16280decf0c56fb4c76bd6e1979b9b60135f254f |
|
MD5 | 026d193aa9f83b61ae74dc1f4349b9d3 |
|
BLAKE2b-256 | 5f7b0297f416339ba43512bfeea976f5701cfe1ec06709b098c2e54c710aca57 |
Provenance
File details
Details for the file mangum-0.18.0-py3-none-any.whl
.
File metadata
- Download URL: mangum-0.18.0-py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf71aa89bd655d465ece62c9c336be6b537eb297cfc72f7ea463aabc5eda2e6a |
|
MD5 | 54c5ff54feb228a8a222b8f13ece8743 |
|
BLAKE2b-256 | ef2596b21305063ff9cc609b2a50b178f9bff4dda4fc29e3ce6ce71b91f5c85d |