Muffin -- is a fast, lightweight and asyncronous ASGI web-framework for Python 3.
- ASGI compatible;
- Competitive Performance;
- All async python libraries are supported (Asyncio, Trio, Curio);
- Send HTTP (text, html, json, stream, file, http errors) responses
- Support WebSockets, Server Side Events
Docs are available at https://klen.github.io/muffin/. Pull requests with documentation enhancements and/or fixes are awesome and most welcome.
Contents
We recommend using the latest version of Python. The library supports Python 3.8 and newer (PyPy-3.9+ are supported too).
Muffin should be installed using pip:
pip install muffin
The command will install minimal configuration.
To install Muffin with gunicorn, uvicorn, uvloop, httptools use the command:
$ pip install muffin[standard]
These distributions will be installed automatically when installing Muffin.
- ASGI-Tools - ASGI Toolkit
- Modconfig - Simple hierarchic configuration manager
Example "Hello User" with the Muffin:
import muffin
app = muffin.Application()
@app.route('/', '/hello/{name}')
async def hello(request):
name = request.path_params.get('name', 'world')
return f'Hello {name.title()}!'
What did that code do?
- First we imported the
muffin.Application
class. An instance of this class will be our application. - Next we create an instance of this class.
- We then use the
muffin.Application.route
decorator to tell Muffin what URLs should trigger our handler function. - The function returns the message we want to display in the user's browser.
Save the script as example.py and run it using Uvicorn (or another ASGI server):
$ uvicorn example:app
Open http://localhost:8000, http://localhost:8000/hello/username in your browser. Enjoy!
The list of some Muffin plugins (please make PR if you want to provide more):
Jinja2 templates (asyncio/trio/curio)
Signed Cookie-Based HTTP sessions (asyncio/trio/curio)
Work with OAuth (authorization, resources loading) (asyncio/trio/curio)
Sentry integration (asyncio/trio/curio)
Peewee support (SQL, ORM) (asyncio/trio/curio)
Localization support (asyncio/trio/curio)
Work with SQL databases (asyncio only)
Work with Mongo DB (asyncio only)
The package provides enhanced support for writing REST APIs (asyncio/trio/curio)
Redis support
Automatically build Admin UI
Prometheus metrics exporter
You could find some tests here: http://klen.github.io/py-frameworks-bench/
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/muffin/issues
Development of The Muffin happens at: https://github.com/klen/muffin
Muffin > 0.40 (completelly rewriten from scratch)
Muffin < 0.40 (based on AIOHTTP)
Licensed under a MIT license.