跳转到主要内容

AWS Lambda支持ASGI应用

项目描述

Mangum

Package version PyPI - Python Version

Mangum是运行ASGI应用的适配器,用于处理Function URL、API Gateway、ALB和Lambda@Edge事件。

文档: https://mangum.fastapiexpert.com/

功能

安装

pip install mangum

示例

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")

或使用框架

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")

项目详情


发布历史 发布通知 | RSS源

下载文件

下载您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

mangum-0.19.0.tar.gz (85.8 kB 查看哈希值)

上传时间

构建分发

mangum-0.19.0-py3-none-any.whl (17.1 kB 查看哈希值)

上传时间 Python 3

由...