litestar
Use when building, reviewing, or debugging a Litestar app — handlers, controllers/routers, dependency injection, DTOs, middleware, lifecycle hooks, templating, static files, websockets, or testing. Triggers on: "Litestar", an app that fails at startup after adding a handler or moving imports behind `TYPE_CHECKING`, sync-handler thread warnings, custom 404/405 handlers that never fire, `Provide`/`Dependency` wiring, or DTO configuration. Not a source of truth for generic FastAPI/Starlette guidance or deep ORM internals.
- License 许可
- Unlicense
- 最近更新
- 2026-10-28
- Stars
- ★ 4
- Forks
- 0
01 前言 Front Matter
- name
- litestar
- description
- Use when building, reviewing, or debugging a Litestar app — handlers, controllers/routers, dependency injection, DTOs, middleware, lifecycle hooks, templating, static files, websockets, or testing. Triggers on: "Litestar", an app that fails at startup after adding a handler or moving imports behind `TYPE_CHECKING`, sync-handler thread warnings, custom 404/405 handlers that never fire, `Provide`/`Dependency` wiring, or DTO configuration. Not a source of truth for generic FastAPI/Starlette guidance or deep ORM internals.
02 资源文件 10
- 参考文档evals/evals.json4.1 KB
- 参考文档evals/trigger-evals.json4.5 KB
- 参考文档references/architecture-layers.md7.6 KB
- 参考文档references/dependencies-dto.md8.9 KB
- 参考文档references/handlers-requests.md8.0 KB
- 参考文档references/integrations.md4.6 KB
- 参考文档references/middleware-hooks-errors.md7.7 KB
- 参考文档references/REFERENCE.md3.4 KB
- 参考文档references/templating-static.md6.0 KB
- 参考文档references/websockets-testing.md8.6 KB
03 SKILL.md 正文
Litestar Framework Reference
Use this skill for core Litestar framework implementation and integration: application structure, layered configuration, handlers, requests, dependency injection, DTOs, middleware, lifecycle hooks, exceptions, templating, static files, testing, websockets, and guards. Open the single best reference file from the routing table, add a second only when the task clearly crosses domains, and implement with verified Litestar patterns, not generic ASGI guesses.
Critical Rules
- Use semantic HTTP decorators - Prefer
@get,@post,@put,@patch,@delete, not@route(), unless multi-method handling is truly required. - Annotate everything - Litestar requires full argument and return type annotations for handlers. Missing annotations fail app startup.
- Keep runtime types available - Handler and dependency annotations are inspected at runtime.
TYPE_CHECKING-only imports can break signature parsing unless you providesignature_typesorsignature_namespace. - Decide sync execution explicitly - Synchronous handlers and dependencies should set
sync_to_thread=Truefor blocking work orFalsefor safe non-blocking work. Implicit sync raises warnings. - Respect layer precedence - For layered settings, the closest layer to the handler wins. Guards are the exception: they accumulate.
- Middleware order is deterministic - Middleware executes app -> router -> controller -> handler, left to right within each layer.
- Dependency keys must match kwargs - Dependency dictionary keys and injected parameter names must match exactly, and scope is limited to the declaring layer.
- Yield dependencies clean up before send - Cleanup runs after the handler returns but before the HTTP response is sent. Cleanup failures are re-raised later as
ExceptionGroup. - Request body defaults to JSON - For forms, multipart, or MessagePack, annotate
datawithBody(media_type=...). File uploads should useUploadFile. - 404 and 405 are app-layer concerns - Litestar raises router-generated
404 Not Foundand405 Method Not Allowedbefore the normal middleware stack and lower-layer exception handlers are called. Handle them at the app layer, and when explaining them, state that timing directly instead of stopping at consequences like "controller middleware does not see them." - Websocket dependencies are connection-scoped - Listener and stream dependencies are evaluated for the connection lifetime, not per message. Do not hold scarce resources for long-lived streams.
- Use current static-files API - Prefer
create_static_files_router().StaticFilesConfigis deprecated in current docs.
When Not To Use This Skill
- Generic FastAPI or Starlette advice - Do not treat Litestar as a drop-in alias. Handler signatures, DI, DTOs, layering, and websockets differ in important ways.
- ORM-specific implementation details - For deep SQLAlchemy, Piccolo, or repository-plugin behavior, use the relevant integration docs or project-specific skill.
- HTMX attribute semantics - Litestar covers HTMX integration points, not full
hx-*behavior. For swap, trigger, and attribute rules, load@htmx. - Project business rules - For app-specific architecture, load the project's custom skill.
Task Routing
All files live in references/. Add the secondary reference only when the task genuinely spans both domains.
| Task | Primary | Secondary |
|---|---|---|
Creating Litestar(...), routers, controllers, app state, lifespan, or layered config |
architecture-layers.md |
— |
| Building HTTP handlers, path params, request parsing, uploads, or custom requests | handlers-requests.md |
— |
Implementing DI, Provide, Dependency, or DTO configuration |
dependencies-dto.md |
— |
| Adding middleware, lifecycle hooks, or exception handlers | middleware-hooks-errors.md |
— |
| Building websocket listeners, streams, or Litestar tests | websockets-testing.md |
— |
| Rendering templates or serving static files | templating-static.md |
— |
| HTMX plugin usage, template engine extras, or framework boundary questions | integrations.md |
— |
| Multipart upload endpoint with DTO or dependency validation | handlers-requests.md |
dependencies-dto.md |
| Custom error handling that fails for 404 or 405 | middleware-hooks-errors.md |
architecture-layers.md |
| HTMX partial rendering in a Litestar app | integrations.md |
templating-static.md |
| Websocket endpoint with auth or connection-scoped resources | websockets-testing.md |
dependencies-dto.md |
Startup failure after TYPE_CHECKING imports or forward refs |
handlers-requests.md |
architecture-layers.md |
| Warnings or confusion around sync handlers and thread offloading | handlers-requests.md |
architecture-layers.md |
| Cross-cutting routing help | REFERENCE.md |
— |
Output Expectations
- Name the reference files used and call out the Litestar rules that matter for the change.
- State the minimum verification steps: tests, startup validation, request or websocket checks, or OpenAPI checks.
- If runtime annotation availability or
sync_to_threadbehavior is part of the issue, say that explicitly instead of giving generic Python advice. - Flag any 2.x vs 3.0 transition or deprecation risk if it affects the task.
04 同仓库更多 Skills
wizard
Generate an interactive bash wizard that walks a human through a manual procedure — third-party setup, credential provisioning, a one-off migration — opening URLs, capturing values, confirming each step, and writing .env files and CI secrets (GitHub and Gitea/Forgejo Actions).
restore-test-pyramid
Analyze the project's E2E suite and push every assertion that doesn't need a real browser down to a faster integration or unit test, proving each migration honest before thinning E2E.
ponytail-debt
Harvest SHORTCUT markers from the codebase and report them grouped by file, flagging any missing upgrade paths.
humanify
Repair an inherited or human-blocked ticket for agent implementation, or finish its explicit human-only outcome.
fix-pr
Repair an existing pull request's review findings and target-branch conflicts, verify the result, and update the same open PR.
feature-milestones
Reconstruct a fragmented backlog as finishable feature milestones with explicit delivery boundaries and an approval-gated tracker update.