跳转到主要内容

松饼是一个快速、简单且支持异步的Python 3(asyncio、trio、curio)网络框架。

项目描述

https://raw.github.com/klen/muffin/develop/docs/static/logo-h200.png

松饼 – 是一个快速、轻量级的Python 3 ASGI 网络框架。

Tests Status Documentation Status PYPI Version Python Versions

特性

  • ASGI 兼容;

  • 竞争性能;

  • 支持所有异步Python库(AsyncioTrioCurio);

  • 发送HTTP(文本、html、json、流、文件、http错误)响应

  • 支持WebSockets、服务器端事件

文档可在https://klen.github.io/muffin/找到。对文档的改进和/或修复的拉取请求非常棒,非常欢迎。

安装

我们建议使用Python的最新版本。该库支持Python 3.8及更高版本(PyPy-3.9+也支持)。

应使用pip安装Muffin

pip install muffin

该命令将安装最小配置。

要使用gunicorn、uvicorn、uvloop、httptools安装Muffin,请使用以下命令

$ pip install muffin[standard]

依赖

安装Muffin时,将自动安装以下发行版。

快速入门

使用Muffin的“Hello User”示例

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()}!'

这段代码做了什么?

  1. 首先我们导入了muffin.Application类。这个类的实例将是我们应用程序。

  2. 然后我们创建了这个类的实例。

  3. 然后我们使用muffin.Application.route装饰器告诉Muffin哪些URL应该触发我们的处理函数。

  4. 该函数返回我们希望在用户浏览器中显示的消息。

将脚本保存为example.py,并使用Uvicorn(或另一个ASGI服务器)运行它

$ uvicorn example:app

在浏览器中打开http://localhost:8000,http://localhost:8000/hello/username。享受吧!

插件概述

一些Muffin插件的列表(如果您想提供更多,请提交PR)

松饼-Jinja2

Jinja2 模板(asyncio/trio/curio)

Tests Status PYPI Version

松饼-Session

基于签名的Cookie HTTP会话(asyncio/trio/curio)

Tests Status PYPI Version

松饼-OAuth

与OAuth(授权、资源加载)一起工作(asyncio/trio/curio)

Tests Status PYPI Version

松饼-Sentry

Sentry集成(asyncio/trio/curio)

Tests Status PYPI Version

松饼-Peewee

Peewee支持(SQL、ORM)(asyncio/trio/curio)

Tests Status PYPI Version

松饼-Babel

本地化支持(asyncio/trio/curio)

Tests Status PYPI Version

松饼-数据库

与SQL数据库一起工作(仅asyncio)

Tests Status PYPI Version

松饼-Mongo

与Mongo DB一起工作(仅asyncio)

Tests Status PYPI Version

松饼-REST

该包提供了增强的REST API编写支持(asyncio/trio/curio)

Tests Status PYPI Version

松饼-Redis

Redis支持

Tests Status PYPI Version

松饼-Admin

自动构建Admin UI

Tests Status PYPI Version

松饼-Prometheus

Prometheus指标导出器

Tests Status PYPI Version

基准测试

您可以在以下位置找到一些测试:[http://klen.github.io/py-frameworks-bench/](http://klen.github.io/py-frameworks-bench/)

错误跟踪器

如果您有任何建议、错误报告或烦恼,请向https://github.com/klen/muffin/issues 的问题跟踪器报告

贡献

Muffin的开发发生在:https://github.com/klen/muffin

贡献者

Muffin > 0.40(完全重写)

Muffin < 0.40(基于AIOHTTP)

许可证

许可协议:MIT[MIT license](https://open-source.org.cn/licenses/MIT).

支持者

AWSAWS 云计算和安全赞助商 DatadogDatadog 监控 FastlyFastly CDN GoogleGoogle 下载分析 MicrosoftMicrosoft PSF赞助商 PingdomPingdom 监控 SentrySentry 错误日志 StatusPageStatusPage 状态页面