{"id":2113,"library":"mangum","title":"Mangum","description":"Mangum is an adapter designed to run ASGI (Asynchronous Server Gateway Interface) applications, such as FastAPI, Starlette, Quart, and Django, within AWS Lambda environments. It handles various AWS event types including Function URLs, API Gateway (HTTP and REST APIs), Application Load Balancer, and CloudFront Lambda@Edge. The library is actively maintained, with frequent releases, and is currently at version 0.21.0.","status":"active","version":"0.21.0","language":"en","source_language":"en","source_url":"https://github.com/Kludex/mangum","tags":["AWS Lambda","ASGI","Serverless","FastAPI","Starlette","Quart","Django"],"install":[{"cmd":"pip install mangum","lang":"bash","label":"Install Mangum"}],"dependencies":[{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"symbol":"Mangum","correct":"from mangum import Mangum"}],"quickstart":{"code":"from fastapi import FastAPI\nfrom mangum import Mangum\n\napp = FastAPI()\n\n@app.get(\"/hello\")\nasync def read_root():\n    return {\"message\": \"Hello from FastAPI on Lambda!\"}\n\nhandler = Mangum(app)\n\n# To test locally, you would typically run with uvicorn:\n# uvicorn main:app --reload --port 8000\n# For Lambda, `handler` is the entry point defined in your function configuration.","lang":"python","description":"This quickstart demonstrates how to wrap a simple FastAPI application with Mangum to make it deployable as an AWS Lambda function. The `handler` object is the entry point for AWS Lambda, which Mangum uses to convert Lambda events into ASGI requests for your application."},"warnings":[{"fix":"Upgrade your Python runtime to 3.9 or later or pin your Mangum dependency to `<0.20.0`.","message":"Mangum dropped official support for Python 3.7 and Python 3.8 in version 0.20.0. Applications targeting these Python versions should remain on an older Mangum release (e.g., 0.19.0 or earlier) or upgrade their Python runtime to 3.9 or newer.","severity":"breaking","affected_versions":">=0.20.0"},{"fix":"Initialize Mangum with `handler = Mangum(app, api_gateway_base_path=\"/your/stage/path\")` and configure your FastAPI app with `app = FastAPI(root_path=\"/your/stage/path\")` as needed.","message":"When deploying FastAPI applications behind AWS API Gateway with custom base paths or stages, incorrect routing ('not found' errors) can occur. It's often necessary to configure `api_gateway_base_path` in the Mangum handler and/or `root_path` in your FastAPI app to match the API Gateway setup.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set `lifespan=\"on\"` for explicit lifespan management or `lifespan=\"auto\"` if your application framework supports it and you want Mangum to automatically handle it.","message":"The `lifespan` parameter (defaulting to `\"off\"` in many examples) controls the ASGI lifespan events (startup/shutdown). Setting it to `\"on\"` or `\"auto\"` is crucial for applications that require startup tasks (e.g., database connections) or shutdown cleanup. Using `\"off\"` will prevent these events from running.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Monitor Mangum's GitHub issues and releases for updates regarding asyncio event loop management and potential migration steps.","message":"Version 0.21.0 has introduced a `DeprecationWarning` related to `asyncio.get_event_loop` during Mangum initialization, indicating a potential shift in how event loops are managed or accessed. While currently a warning, it may foreshadow future breaking changes.","severity":"deprecated","affected_versions":"0.21.0"},{"fix":"Consult Mangum's documentation on `text_mime_types` and `exclude_headers` parameters to correctly configure how different content types are processed.","message":"Handling binary media types (e.g., images, PDFs) or certain text-based content types (e.g., `application/json` with specific charsets) requires careful configuration to prevent data corruption. Headers like `Content-Type` might need explicit handling or inclusion in `text_mime_types` for proper encoding/decoding.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}