Modern async ASGI API framework · formerly Starlite · verified against Litestar 2.24 (2026)

Litestar cheat sheet

Litestar is a batteries-included, high-performance ASGI framework for building APIs — a FastAPI alternative (and the framework formerly known as Starlite). Type-hinted route handlers do parsing, validation, and OpenAPI docs for you, powered by ultra-fast msgspec. It ships with layered dependency injection, class-based controllers, DTOs, guards, plugins, and a real CLI — opinionated where it helps, flexible where it counts. Supports msgspec / dataclasses / Pydantic v1&v2 / attrs / TypedDict. This sheet targets Litestar 2.24.

app & routes params & body structure & DI DTOs operate & ship gotcha most common

Verified 2026-08-25 against the official docs at docs.litestar.dev (Litestar 2.24.0, 2026-06; Python 3.8–3.14). Import name is litestar (renamed from starlite in 2.0). Served by any ASGI server (uvicorn) via the built-in litestar run.

Outline

Write typed @get/@post handlers, register them on a Litestar app, and let type hints handle params, body validation, and OpenAPI. Then structure with controllers, inject dependencies, shape I/O with DTOs, and ship.

Handle

  1. 1 · Install & app
  2. 2 · Route handlers & params
  3. 3 · Body & validation

Structure

  1. 4 · Controllers & routers
  2. 5 · Dependency injection
  3. 6 · DTOs

Operate & ship

  1. 7 · Lifespan, state, plugins
  2. 8 · OpenAPI, guards, testing
  3. 9 · Gotchas
  4. Worth memorizing

Handle

Create the app and write typed handlers that parse and validate themselves.

1Install & app2.24
2Route handlers & params@get @post @put ...
3Body & validationdata: Model

Structure

Group routes, inject dependencies, and control serialization.

4Controllers & routersgroup routes
5Dependency injectionProvide()
6DTOsshape (de)serialization

Operate & ship

Wire up lifecycle, docs, security, and tests.

7Lifespan, state, pluginsapp lifecycle
8OpenAPI, guards, testingdocs, auth, tests
!Common gotchasread before shipping

Worth memorizing

import litestar (ex-starlite)renamed at 2.0
Litestar(route_handlers=[...])register everything reachable
@get/@post async def -> Typereturn annotation = serialize + OpenAPI
/{id:int} + id: intpath param typed in the path
data: Modelbody parsed + validated (msgspec fastest)
Controller.path + Router(path=)group & nest routes
dependencies={"db": Provide(fn)}inject by matching param name
DTOConfig(exclude=...) + dto/return_dtoshape in/out; DTOData for PATCH
on_startup / on_shutdown / lifespanapp.state shared store
/schema OpenAPI autoSwagger/ReDoc/Scalar/Stoplight
guards=[fn] for authlayered like deps/middleware
create_test_client([...])in-process tests, no server