Skip to main content

AWS Lambda & API Gateway support for ASGI

Project description

Mangum

Package version Build Status

Mangum is an adapter for using ASGI applications with AWS Lambda & API Gateway.

Documentation: https://erm.github.io/mangum

Requirements

Python 3.6+

Installation

pip3 install mangum

Usage

The adapter class Mangum accepts the following optional arguments:

  • enable_lifespan : bool (default=True)

    Specify whether or not to enable lifespan support.

  • api_gateway_base_path : str (default=None)

    Base path to strip from URL when using a custom domain name.

Event and context

The AWS Lambda handler has event and context parameters. These are available in the ASGI scope object:

scope['aws.event']
scope['aws.context']

Example

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, enable_lifespan=False) # disable lifespan for raw ASGI example

WebSockets (experimental)

The adapter currently provides some basic WebSocket support using boto3 with DynamoDB. To install Mangum with the optional dependency:

pip3 install mangum[full]

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.7.2.tar.gz (8.5 kB view details)

Uploaded Source

File details

Details for the file mangum-0.7.2.tar.gz.

File metadata

  • Download URL: mangum-0.7.2.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.1

File hashes

Hashes for mangum-0.7.2.tar.gz
Algorithm Hash digest
SHA256 404cc782c8bc797ac2e8651e6051ba73a18e2c2e3d74cc3df9c318f8903d36ef
MD5 32fdfe085caf03b865d7b33dfdf50502
BLAKE2b-256 82446ac0d40f4f33bfa9e2c1504112b8aaa232bdbcf1a259cd5222c02b89110e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page