Lihil Official
The Official website of python webframework lihil
from lihil import Lihil, Route, Streamfrom openai import OpenAIfrom openai.types.chat import ChatCompletionChunk as Chunkfrom openai.types.chat import ChatCompletionUserMessageParam as MessageIngpt = Route("/gpt", deps=[OpenAPI])def message_encoder(chunk: Any) -> bytes:if not chunk.choices:return b""return chunk.choices[0].delta.content.encode() or b""@gpt.sub("/messages").post(encoder=message_encoder)async def add_new_message(client: OpenAPI, question: MessageIn, model: str) -> Stream[Chunk]:async for chunk in client.responses.create(messages=[question], model=model, stream=True):yield chunk
50%-100%
Faster than other ASGI frameworks, more for larger app.benchmarks
100%
Test Covered and strictly typed
> 45K
RPS(per CPU thread)
Get Started in Seconds
Lihil is designed for simplicity without sacrificing power. Install with pip and start building your next Python web application.
Create a REST API in minutes
from lihil import Lihil, HTTPException, Struct, Route, Param, Annotated, Emptyclass TodoItem(Struct):id: inttitle: strcompleted: bool = Falsetodo = Route("/todos", deps=[TodoRepo])@todo.getasync def get_todos(todo_repo: TodoRepo, n: Annotated[int, Param(lt=100)]):return await todo_repo.list_todos()@todo.postasync def create_todo(item: TodoItem, todo_repo: TodoRepo) -> Annotated[Empty, 201]:await todo_repo.add(item)if __name__ == "__main__":lhl = Lihil(todo)lhl.run(__file__)
Why Choose lihil?
A clean, powerful Python web framework built for modern apps.
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 for endpoints, routes, and middlewares – no extra setup required.
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.
Join the Community
Lihil is backed by a growing community of Python developers. Get support, contribute, and help shape the future of fast Python web development.
Ready to build something amazing?
Join the growing community of developers using Lihil to build fast, robust, and scalable web applications.
Get Started Now