from lihil import Lihil, Route, EventStream, SSE, Paramfrom .api.param import UUID_PATTERNUUIDStr = Annotated[str, Param(min_length=36, pattern=UUID_PATTERN)]@messages.postasync def send_message_v1(session_id: UUIDStr,request: AgentRequest,agent: Annotated[IAgent, use(get_agent)],) -> EventStream:async_gen = agent.handle(request.content, user_id=request.user, session_id=session_id)yield SSE(event="open", data=await anext(async_gen))async for ans in async_gen:yield SSE(event="token", data=ans)yield SSE(event="done", data="")
Lihil is designed for simplicity without sacrificing power. Install with pip and start building your next Python web application.
from lihil import Lihil, HTTPException, Struct, Route, Param, Annotated, Emptyclass TodoItem(Struct):id: inttitle: strcompleted: bool = Falsetodo = Route("/todos", deps=[TodoRepo])PosInt = Annotated[int, Param(gt=0)]Todos = list[TodoItem]@todo.getasync def get_todos(todo_repo: TodoRepo, n: PosInt) -> Todos:return await todo_repo.list_todos()CREATED = Annotated[Empty, 201]@todo.postasync def create_todo(item: TodoItem, todo_repo: TodoRepo) -> CREATED:await todo_repo.add(item)if __name__ == "__main__":lhl = Lihil(todo)lhl.run(__file__)
msgspecを使用してパス、クエリ、ヘッダー、ボディからのリクエストデータを自動的に解析・検証。Pydanticより12倍高速で25倍メモリ効率が良い。
型ヒントに基づいて依存関係を注入。ファクトリー、非同期、スコープ、シングルトンをサポート - すべて超高速。
クリーンで型安全なAPIでWebSocket接続を処理。内蔵のWebSocketテストクライアントで簡単にテスト可能。
OpenAPIドキュメントと問題詳細を自動生成。カスタム例外は明確なAPIレスポンスに変換される。
JWTとOAuth2の内蔵サポート。認証オブジェクトは型安全でシリアライズ可能。
プロセス内外でイベントを効率的に発行・処理する内蔵イベントシステム。
エンドポイント、ルート、ミドルウェア用の内蔵テストクライアント - 追加設定不要。
最小限のメモリ使用量に最適化。GCオーバーヘッドが削減され、負荷下でのサービス安定性が向上。
AIを念頭に設計。SSE、MCP、リモートハンドラーの内蔵サポートが近日公開予定。
Lihil is backed by a growing community of Python developers. Get support, contribute, and help shape the future of fast Python web development.