# Litestar — High-Performance Python ASGI Web Framework > Litestar is a powerful, flexible, and opinionated ASGI web framework for building modern Python APIs with class-based controllers, dependency injection, and automatic OpenAPI docs. ## Install Save as a script file and run: # Litestar — High-Performance Python ASGI Web Framework ## Quick Use ```bash pip install litestar[standard] # Create app.py cat << EOF > app.py from litestar import Litestar, get @get("/") async def index() -> dict[str, str]: return {"hello": "world"} app = Litestar([index]) EOF # Run with uvicorn litestar run ``` ## Introduction Litestar (formerly Starlite) is a production-ready ASGI framework for Python that emphasizes performance, type safety, and developer experience. It provides a batteries-included approach with built-in support for OpenAPI documentation, dependency injection, data validation via msgspec or Pydantic, and ORM integration, while remaining extensible through a robust plugin system. ## What Litestar Does - Serves async HTTP APIs with class-based controllers and function-based route handlers - Generates OpenAPI 3.1 documentation automatically from type annotations - Provides built-in dependency injection with support for sync and async providers - Validates request and response data using msgspec, Pydantic, or attrs - Includes WebSocket support, middleware, guards, and lifecycle hooks out of the box ## Architecture Overview Litestar is built on top of the ASGI specification and uses a layered architecture. The core router maps incoming requests to handlers through a trie-based routing algorithm for fast path matching. Middleware, guards, and dependencies are resolved per-request using an internal dependency injection container. Data serialization and validation leverage msgspec by default for performance, with optional Pydantic support. The framework generates OpenAPI schemas at startup by inspecting handler type annotations. ## Self-Hosting & Configuration - Install via pip with optional extras: `pip install litestar[standard]` for recommended defaults - Configure the application through the `Litestar()` constructor or dedicated config objects - Deploy with any ASGI server: uvicorn, hypercorn, granian, or daphne - Use environment variables and `.env` files for secrets and per-environment settings - Enable structured logging and exception handling through built-in middleware ## Key Features - Trie-based router delivering fast path resolution regardless of route count - First-class support for msgspec providing faster serialization than Pydantic - Class-based controllers enabling grouped route handlers with shared dependencies - Plugin system for SQLAlchemy, Tortoise ORM, Piccolo, and custom integrations - Built-in rate limiting, CORS, CSRF protection, and session middleware ## Comparison with Similar Tools - **FastAPI** — more popular and larger ecosystem, but Litestar offers class-based controllers and native msgspec support - **Starlette** — lower-level ASGI toolkit that Litestar originally built upon before forking - **Django Ninja** — adds FastAPI-like syntax to Django, ties you to the Django ecosystem - **Sanic** — async framework with its own server, less focus on type-driven validation - **Falcon** — minimalist ASGI/WSGI framework optimized for REST APIs with less built-in tooling ## FAQ **Q: What happened to Starlite?** A: Starlite was renamed to Litestar in version 2.0. The project has its own independent codebase and is not a fork of Starlette. **Q: Can I use Pydantic with Litestar?** A: Yes. Litestar supports Pydantic v1 and v2 as validation backends alongside msgspec and attrs. Install with `pip install litestar[pydantic]`. **Q: How does Litestar compare to FastAPI in performance?** A: Benchmarks vary by workload, but Litestar with msgspec typically matches or exceeds FastAPI throughput due to faster serialization and trie-based routing. **Q: Does Litestar support WebSockets?** A: Yes. Litestar includes WebSocket handlers with the same dependency injection and middleware capabilities as HTTP handlers. ## Sources - https://github.com/litestar-org/litestar - https://docs.litestar.dev/ --- Source: https://tokrepo.com/en/workflows/74a362ce-3cf6-11f1-9bc6-00163e2b0d79 Author: Script Depot