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.19.0.tar.gz
.
File metadata
- Download URL: mangum-0.19.0.tar.gz
- Upload date:
- Size: 85.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e388e7c491b7b67970f8234e46fd4a7b21ff87785848f418de08148f71cf0bd6 |
|
MD5 | 4ee02566e6c5ea6dc5b0eed0efa62bff |
|
BLAKE2b-256 | 97e06ee9bfa27226252a449cba12fc57d3f1c3ce661813377ab33e29245389a4 |
File details
Details for the file mangum-0.19.0-py3-none-any.whl
.
File metadata
- Download URL: mangum-0.19.0-py3-none-any.whl
- Upload date:
- Size: 17.1 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 | e500b35f495d5e68ac98bc97334896d6101523f2ee2c57ba6a61893b65266e59 |
|
MD5 | f4a8fd6e6eaa2049d8d1e74fbe8e2a2e |
|
BLAKE2b-256 | 77ecdd1cae5f6b1b4a08c01de587b45e889036b2f8c06408621e0cb273909965 |