ASGI to AWS Lambda adapter
Project description
mangum
AWS Lambda/API Gateway support for ASGI applications.
Work in progress
Currently only supports HTTP responses, but there is an open issue here here for working out potential WebSocket support.
Installation
pip install mangum
Note: The package on PyPi may be significantly behind the active development, so you probably want to clone the repo instead.
Examples
Below is a basic "hello world" ASGI application:
from mangum import asgi_handler
class App:
def __init__(self, scope) -> None:
self.scope = scope
async def __call__(self, receive, send) -> None:
message = await receive()
if message["type"] == "http.request":
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [[b"content-type", b"text/plain"]],
}
)
await send({"type": "http.response.body", "body": b"Hello, world!"})
def lambda_handler(event, context):
return asgi_handler(App, event, context)
Any ASGI framework should work as well, here is the above example using Starlette:
from mangum import asgi_handler
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
app = Starlette()
@app.route("/")
def homepage(request):
return PlainTextResponse("Hello, world!")
def lambda_handler(event, context):
return asgi_handler(app, event, context)
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
mangum-0.1.0.tar.gz
(4.0 kB
view details)
File details
Details for the file mangum-0.1.0.tar.gz
.
File metadata
- Download URL: mangum-0.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f97129e4627624d6406d293f96a7c69f9f2ce33d570f6a8148f4e3502411e0f |
|
MD5 | 209eb3149053085a86695a82d742477c |
|
BLAKE2b-256 | e1fbfde2946c1306fb7dd33242dfc1d43154d76a88afd9dcba8e79a4520a78b3 |