Starlette高性能 Python 的 Web 开发框架
Starlette 是一个轻量级的 ASGI 框架和工具包,特别适合用来构建高性能的 asyncio 服务.
Starlette 的主要特性:
- 性能表现优异
 - WebSocket 支持.
 - GraphQL 支持.
 - 进程内的后台任务执行
 - 启动和关闭服务的事件触发
 - 测试客户端构建于 
requests. - 支持 CORS, GZip, Static Files, Streaming 响应.
 - 支持会话和 Cookie
 - 100% 测试覆盖率
 - 100% 类型注解
 - 无依赖
 
示例代码:
from starlette.responses import JSONResponse
from starlette.routing import Route
async def homepage(request):
    return JSONResponse({'hello': 'world'})
app = Starlette(debug=True, routes=[
    Route('/', homepage),
]) 
运行:
$ uvicorn example:app
评论
