Muffin is a fast, simple and asyncronous web-framework for Python 3 (asyncio, trio)
Project description
Muffin – is a fast, lightweight and asyncronous ASGI web-framework for Python 3.
Features
ASGI compatible;
Parse ASGI scope, get url, headers, cookies, read a request’s data/json/form-data
Send HTTP (text, html, json, stream, file, http errors) responses
Work with WebSockets
Docs are available at https://klen.github.io/muffin/. Pull requests with documentation enhancements and/or fixes are awesome and most welcome.
Installation
We recommend using the latest version of Python. The library supports Python 3.7 and newer.
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]
Dependencies
These distributions will be installed automatically when installing Muffin.
ASGI-Tools - ASGI Toolkit
Modconfig - Simple hierarchic configuration manager
Quickstart
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. The first argument is the name of the application.
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!
Plugins overview
The list of some Muffin plugins (please make PR if you want to provide more):
Muffin-Jinja2
Jinja2 templates (asyncio/trio/curio)
Muffin-Session
Signed Cookie-Based HTTP sessions (asyncio/trio/curio)
Muffin-OAuth
Work with OAuth (authorization, resources loading) (asyncio/trio/curio)
Muffin-Sentry
Sentry integration (asyncio/trio/curio)
Muffin-Peewee
Peewee support (SQL, ORM) (asyncio/trio/curio)
Muffin-Babel
Localization support (asyncio/trio/curio)
Muffin-Databases
Work with SQL databases (asyncio only)
Muffin-Mongo
Work with Mongo DB (asyncio only)
Muffin-REST
The package provides enhanced support for writing REST APIs (asyncio/trio/curio)
Muffin-Redis
Redis support
Muffin-Admin
Automatically build Admin UI
Muffin-Prometheus
Prometheus metrics exporter
Benchmarks
You could find some tests here: http://klen.github.io/py-frameworks-bench/
Bug tracker
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/muffin/issues
Contributing
Development of The Muffin happens at: https://github.com/klen/muffin
Contributors
Muffin > 0.40 (completelly rewriten from scratch)
Muffin < 0.40 (based on AIOHTTP)
License
Licensed under a MIT license (See LICENSE)
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 Distributions
Built Distribution
File details
Details for the file muffin-0.66.0-py3-none-any.whl
.
File metadata
- Download URL: muffin-0.66.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b340db7515af65781ee717146048cf299612f5d02d2d2cc2045cd0217052382c |
|
MD5 | 0f17427a612a4baa808dd97549c4de79 |
|
BLAKE2b-256 | da0e2ae5fb3b155364705b6cdf4cba3fbc51da36a4d7cdc9deb516b5ac7e30bc |