闪亮的小ASGI框架.
<p对齐="中心"> < 图片> < source media="(偏好-color-scheme: 暗)" srcset="https://raw.githubusercontent.com/Kludex/starlette/main/docs/img/starlette_dark.svg"宽="420px". < source media="(偏好-彩色-scheme:光)" srcset="https://raw.githubusercontent.com/Kludex/starlette/main/docs/img/starlette.svg"宽度="420px".
</图片>
(中文(简体) ).<p对齐="中心"> ✨> 闪亮的小ASGI框架。 QQ/em >
(中文(简体) ).-- -- . . . -- -- . . .
** 文件**:<a href='https://starlette.dev/"目标='' blank'> ZZ3ZZ
** 来源代码**:<a href="https://github.com/Kludex/starlette"目标=" blank". ZZ5ZZ
-- -- . . .
星际迷航
Starlette是一个轻量级[ASGI][asgi]框架/工具基特, 这是在Python中构建Aync网络服务的理想.
它已经做好了生产准备,并提供了以下内容:
Ayncio'和trio'后端兼容。□ 安装
(原始内容存档于2019-09-29) (英语). ```shell $ pip install starlette
您也会想要安装一个 ASGI 服务器,例如 [uvicorn] (https://uvicorn.dev) 或任何[其他 ASGI 服务器执行 (https://asgi.readthedocs.io/en/latest/implementations.html#servers).
ZZ1ZZ
□ 实例
(原始内容存档于2019-09-29). ```python title="main.py"
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
async def homepage(request):
return JSONResponse({'hello': 'world'})
routes = [
Route("/", endpoint=homepage)
]
app = Starlette(debug=True, routes=routes)然后使用 Uvicorn 运行应用程序 :
ZZCODE3 乐团
□ 依赖性
Starlette只要求`Anyio',以下是可选的:
httpx2 ' [httpx2] -- -- 如果想要使用试验站 ' ,则必须使用。当作用域没有主机时,Request.url 会将 // 路径转换为权限
`include_query_params` 不支持多值
子应用程序中的生命周期事件
添加可配置的媒体处理器和 Request.data()
主机头攻击: `url_for()` 不应信任未验证的主机头
支持 103 种早期提示
TestClient.request 不会尊重 stream=True
在安装路由时正确处理尾随斜杠
url_for 仅返回具有权限组成部分的 URL