Mangum provides support for the following AWS HTTP Lambda Event Source:
- API Gateway (Event Examples)
- HTTP Gateway (Event Examples)
- Application Load Balancer (ALB) (Event Examples)
- CloudFront Lambda@Edge (Event Examples)
from fastapi import FastAPI
from fastapi.middleware.gzip import GZipMiddleware
from mangum import Mangum
app = FastAPI()
app.add_middleware(GZipMiddleware, minimum_size=1000)
@app.get("/")
async def main():
return "somebigcontent"
handler = Mangum(app, TEXT_MIME_TYPES=["application/vnd.some.type"])Binary responses are determined using the Content-Type and Content-Encoding headers from the event request and a list of text MIME types.
By default, all response data will be base64 encoded and include isBase64Encoded=True in the response except the default text MIME types and any MIME types included in the TEXT_MIME_TYPES list setting.
The following types are excluded from binary responses by default:
application/jsonapplication/javascriptapplication/xmlapplication/vnd.api+json
Additionally, any Content-Type header prefixed with text/ is automatically excluded.
If the Content-Encoding header is set to gzip or br, then a binary response will be returned regardless of MIME type.
The HTTPCycle is used by the adapter to communicate message events between the application and AWS. It is a state machine that handles the entire ASGI request and response cycle.
::: mangum.protocols.http.HTTPCycle :docstring: :members: run receive send
::: mangum.protocols.http.HTTPCycleState :docstring: