Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Kludex/mangum
AWS Lambda support for ASGI applications
https://github.com/Kludex/mangum
api-gateway asgi asyncio aws aws-lambda django fastapi lambda python python3 quart sanic serverless starlette
Last synced: about 2 months ago
JSON representation
AWS Lambda support for ASGI applications
- Host: GitHub
- URL: https://github.com/Kludex/mangum
- Owner: Kludex
- License: mit
- Created: 2019-01-14T11:49:29.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-06-13T08:48:30.000Z (5 months ago)
- Last Synced: 2024-09-14T17:08:10.715Z (about 2 months ago)
- Topics: api-gateway, asgi, asyncio, aws, aws-lambda, django, fastapi, lambda, python, python3, quart, sanic, serverless, starlette
- Language: Python
- Homepage: https://mangum.io/
- Size: 3.62 MB
- Stars: 1,668
- Watchers: 16
- Forks: 123
- Open Issues: 35
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Mangum
Mangum is an adapter for running [ASGI](https://asgi.readthedocs.io/en/latest/) applications in AWS Lambda to handle Function URL, API Gateway, ALB, and Lambda@Edge events.
***Documentation***: https://mangum.io/
## Features
- Event handlers for API Gateway [HTTP](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html) and [REST](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html) APIs, [Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html), [Function URLs](https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html), and [CloudFront Lambda@Edge](https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html).
- Compatibility with ASGI application frameworks, such as [Starlette](https://www.starlette.io/), [FastAPI](https://fastapi.tiangolo.com/), [Quart](https://pgjones.gitlab.io/quart/) and [Django](https://www.djangoproject.com/).
- 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](https://www.serverless.com/) and [AWS SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html).
- Startup and shutdown [lifespan](https://asgi.readthedocs.io/en/latest/specs/lifespan.html) events.
## Requirements
Python 3.7+
## Installation
```shell
pip install mangum
```## Example
```python
from mangum import Mangumasync 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:
```python
from fastapi import FastAPI
from mangum import Mangumapp = 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")
```