Zappa vs Mangum

Zappa vs Mangum

Zappa and Mangum[1] are Python libraries that parse events from Amazon's API Gateway and feed them into a Python WSGI or ASGI application. This allows you to put API Gateway in front of a Lambda runtime, have Lambda execute the service requests that come in through API Gateway, and code your service logic in any Python web framework.

But what framework should you use for your next serverless REST API? I say Mangum. Both are mature products and Zappa appears to have been around longer and has more features implemented to show for it. But there are some key features, ranging from nice to have to increasingly required, that Mangum is delivering on and Zappa isn't that makes me recommend Mangum for future uses.

First, Zappa's maintainership hasn't been great. There is constant activity on Zappa, but a lot of low-hanging bug fixes and feature improvements, like the ones I am detailing here, haven't been implemented. Even if it is possible for Zappa to catch up and get these things knocked out the lack of responsible maintainership points to a dying project.

Zappa goes beyond being a shim library to handle WSGI requests and has grown up a small ecosystem of functionality, including the ability to package Lambda zip deployments on your behalf, deploy lambdas for you, create CloudFormation JSON to manage your configuration outside of Zappa, invoke one-off functionality in Lambda outside of the API Gateway request cycle (like a maintenance command), and tail Lambda logs in real time. This is all extremely useful stuff and makes Zappa much more appealing than the bare-bones Mangum. However, Zappa's functionality has slowed its ability to keep up with the latest AWS features. Zappa can only assemble Lambda deployment zip files for x86 Lambdas, not the new, cost-effective Graviton 64-bit ARM CPUs. It also only supports v1 of the API Gateway events, locking you out of a simpler and more cost-effective v2 deployment. Finally, Zappa does not have any way to pass the original Lambda event on to your application code and only extracts the minimum data from the event required to invoke a WSGI request (omitting things such as the IP address of the original request made to API Gateway). This is a really unfortunate one-two punch where Zappa isn't even letting you work around its shortcomings.

If you jump to Mangum you'll have a bit more of a pull ahead of you. There's no tooling to package and deploy a Lambda for you so you'll have to do some DevOps work to create that pipeline. But if you dig in and get it done yourself you could assemble a Docker image for Lambda on the the Graviton CPUs, something not available to you at all with Zappa. Using a Docker image lets you get around the 50 MB limit on zip files for the Lambda deployment. If you are using one of the many WSGI-only web frameworks you may be put off by Mangum's lack of support for WSGI. However, there is an open source WSGI-to-ASGI adapter that will let you connect any existing WSGI code into Mangum, so ASGI-only is not as limiting as it sounds. Mangum is also doing a better job at parsing the API Gateway event payloads, supports the latest version of API Gateway, and even lets you write WebSocket APIs.

Taking the tradeoffs into account, even though Mangum does not offer as much overall functionality as Zappa does right now, it still supports the core, important functionality that you'll increasingly need to use in the future, like 64-bit ARM Lambdas, support for the new AWS APIs, and support for ASGI frameworks. For those reasons I recommend using Mangum for new API Gateway projects with Python.


[1] Zappa is named after musician Frank Zappa who needs no introduction. Mangum is named after Jeff Mangum, of the band Neutral Milk Hotel, best known for an album about Anne Frank and "semen stains the mountaintops."