pip install "litestar[standard]"★Thestandardextra bundles uvicorn, the CLI, and templating. Plainlitestaris the minimal core.from litestar import Litestar, get @get("/") async def hello() -> dict[str, str]: return {"hello": "world"} app = Litestar(route_handlers=[hello])★The whole app. Register handlers onLitestar(route_handlers=[...]). The return annotation drives serialization and the OpenAPI schema.litestar run --reload # dev server (finds app.py:app) litestar routes · litestar version★Built-in CLI. It auto-discoversappinapp.py; otherwise set--app module:apporLITESTAR_APP.
from litestar import get, post, put, patch, delete★One decorator per HTTP method — each is an async handler by default. (A sync handler needs@get(..., sync_to_thread=True).)@get("/users/{user_id:int}") async def get_user(user_id: int) -> User: ...★Path params declare a type in the path ({user_id:int}) and appear as a matching typed argument — parsed & validated.@get("/search") async def search(q: str, limit: int = 10) -> list[Hit]: ...★Query params = handler args not in the path. Defaults make them optional;Parameter(...)adds constraints/aliases/headers/cookies.
from msgspec import Struct class User(Struct): name: str age: int★msgspecStructis the fastest model — Litestar uses msgspec for validation/serialization. Dataclasses, TypedDict, Pydantic v1/v2, and attrs also work.@post("/users") async def create(data: User) -> User: return data★Annotate a param with a model and it's parsed from the JSON body — automatic validation, a 400 on bad input, zero boilerplate. The conventional name isdata.async def upload(data: bytes = Body(media_type=RequestEncodingType.MULTI_PART)): ...UseBody(...)for form/multipart/URL-encoded bodies and to tune the media type.