The Official website of python webframework lihil
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="")
Faster than other ASGI frameworks, more for larger app. benchmarks
Test Covered and strictly typed
RPS(per CPU thread)
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__)
Automatically parse & validate request data from path, query, headers, and body with msgspec – 12x faster and 25x more memory efficient than Pydantic.
Inject dependencies based on type hints. Supports factories, async, scopes, and singletons – all lightning fast.
Handle WebSocket connections with clean, type-safe APIs. Easily test using the built-in WebSocket test client.
Auto-generate OpenAPI docs and problem details. Custom exceptions are turned into clear API responses.
Built-in support for JWT and OAuth2. Auth objects are type-safe and serializable.
Built-in event system to publish and handle events, both in-process and out-of-process, efficiently.
Built-in test client `LocalClient` for endpoints, routes, and middlewares solely without building the whole App
Optimized for minimal memory usage. GC overhead is reduced, making services more stable under load.
Designed with AI in mind. Built-in support for SSE, MCP, and remote handlers coming soon.
Lihil is backed by a growing community of Python developers. Get support, contribute, and help shape the future of fast Python web development.
Join the growing community of developers using Lihil to build fast, robust, and scalable web applications.
Get Started Now