plugins/litestar/skills/litestar-plugins/SKILL.md
Configure Litestar plugin architecture and ecosystem integrations, including custom Init/DI/serialization/route plugins, SQLAlchemy plugin stacks, Pydantic plugin surfaces, Piccolo DTO usage, and model-bound transport support for dataclasses, msgspec, attrs, and TypedDict. Use when selecting, wiring, or debugging plugin-driven behavior at application boundaries. Do not use for unrelated framework setup that does not involve Litestar plugin protocols, plugin registration, or plugin-backed transport/model integration.
npx skillsauth add alti3/litestar-skills litestar-pluginsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill when a Litestar app needs plugin-driven behavior, or when the task touches one of the model ecosystems that Litestar integrates through plugins, DTO factories, or OpenAPI schema plugins.
The links previously listed for this skill are partly stale in the latest Litestar docs. Use the current structure below:
usage/plugins/index.html.usage/databases/sqlalchemy/plugins/....PiccoloDTO usage under usage/databases/piccolo.html, not as a separate general plugin page.reference/plugins/....reference/dto/..., not as standalone plugin usage pages.Do not blindly follow old usage/plugins/*.html URLs for every ecosystem. Several now return 404 in the latest docs.
Litestar(..., plugins=[...]), and keep ordering explicit.dto / return_dto declarations when the public contract matters more than boilerplate reduction.InitPluginUse for application composition and startup-time configuration.
on_app_init(self, app_config: AppConfig) -> AppConfig.on_app_init hooks.plugins=[...] list.Use this when the plugin changes application structure.
SerializationPluginProtocolUse when Litestar should auto-create DTOs for supported handler annotations.
supports_type(field_definition) -> bool.create_dto_for_type(field_definition) -> type[AbstractDTO].dto or return_dto.Use this for reducing repeated DTO declarations, not for hiding contract decisions.
DIPluginUse when Litestar needs help understanding constructor type information for dependency injection.
has_typed_init(type_) -> bool.get_typed_init(type_) -> tuple[Signature, dict[str, Any]].Use this for model types whose constructor annotations are not directly recoverable by default inspection.
ReceiveRoutePluginUse when a plugin must observe routes during registration.
receive_route(route: BaseRoute) -> None.Keep this observational. Do not bury broad app mutation here.
OpenAPISchemaPluginProtocolUse when a non-native model/type needs custom OpenAPI schema generation.
is_plugin_supported_type(value) -> bool.to_openapi_schema(field_definition, schema_creator) -> Schema.Use this for schema generation, not request parsing or DTO mutation.
Choose the smallest surface that solves the problem:
AppConfig or install app-wide behavior: use an InitPlugin.DIPlugin.Latest docs still show imports from litestar.plugins.sqlalchemy, but the class reference material is now largely hosted through Advanced Alchemy.
Primary choices:
SQLAlchemyPlugin(config=...): full integration; combines init behavior and serialization support.SQLAlchemyInitPlugin(config=...): session/engine lifecycle and DI only.SQLAlchemySerializationPlugin(): auto-generates SQLAlchemyDTO[...] for supported annotations when no explicit DTO is declared.SQLAlchemyDTO[Model]: explicit DTO when you need contract control.SQLAlchemyInitPlugin behavior in latest docs:
before_send handler.Configuration rules:
SQLAlchemyAsyncConfig for async engines/sessions.SQLAlchemySyncConfig for sync engines/sessions.sync_to_thread=True.engine_dependency_key and session_dependency_key if defaults conflict.before_send_handler.engine_config and session_config for lower-level SQLAlchemy tuning instead of ad hoc patching.Serialization rules:
SQLAlchemySerializationPlugin is functionally equivalent to explicit SQLAlchemyDTO[...] declarations for supported annotations.DTOConfig, separate read/write policies, field exclusions, or PATCH semantics.Latest docs focus on litestar.contrib.piccolo.PiccoloDTO rather than a dedicated plugin page.
Use Piccolo support like this:
dto=PiccoloDTO[Table]return_dto=PiccoloDTO[Table]DTOConfig(exclude={"id"}, partial=True) and DTOData[Table].update_instance(...)Guidance:
litestar-databases.Latest docs expose a broader plugin surface here than for most other model ecosystems.
Available pieces:
PydanticPlugin: broad app integration for Pydantic.PydanticInitPlugin: init-focused integration.PydanticDIPlugin: DI constructor/signature support.PydanticDTO[T]: explicit DTO support for Pydantic models.PydanticSchemaPlugin: OpenAPI schema generation.Important PydanticPlugin / PydanticInitPlugin options:
excludeincludeexclude_defaultsexclude_noneexclude_unsetprefer_aliasvalidate_strictround_tripUse them carefully:
prefer_alias=True when wire format should follow model aliases.validate_strict=True when Pydantic v2 coercion should be tightened.round_trip=True when dump behavior must preserve data for model re-validation or exact round-tripping.Decision rules:
PydanticPlugin when Pydantic behavior should be configured app-wide.PydanticInitPlugin when you want the init/serialization behavior without relying on the broader combined surface.PydanticDIPlugin when dependency constructors are Pydantic models or otherwise need plugin-assisted typed-init extraction.PydanticDTO when API contract control matters more than global plugin defaults.PydanticSchemaPlugin(prefer_alias=...) when schema generation must reflect alias choices.Do not assume that installing PydanticPlugin removes the need for explicit DTOs. Public API contracts still need deliberate read/write shaping.
Latest docs document dataclass support as DataclassDTO, not as a standalone plugin usage page.
Use:
litestar.dto.dataclass_dto.DataclassDTOWhat it provides:
Guidance:
DataclassDTO for transport contracts.InitPlugin concern.Latest docs document msgspec support as MsgspecDTO, not as a standalone plugin usage page.
Use:
litestar.dto.msgspec_dto.MsgspecDTOWhat it provides:
msgspec.Struct models.Guidance:
MsgspecDTO declarations when msgspec models are the transport boundary.Latest docs document attrs support as an OpenAPI schema plugin:
litestar.plugins.attrs.AttrsSchemaPluginlitestar.plugins.attrs.is_attrs_class()Guidance:
Latest docs do not expose a dedicated TypedDict plugin page.
Treat TypedDict support conservatively:
InitPlugin logic composition-focused; do not bury business logic in on_app_init().ReceiveRoutePlugin side effects predictable and registration-time only.Use a custom plugin only when built-in surfaces are insufficient.
from litestar import Litestar, get
from litestar.config.app import AppConfig
from litestar.di import Provide
from litestar.plugins import InitPlugin
@get("/health")
def healthcheck(version: str) -> dict[str, str]:
return {"status": "ok", "version": version}
def provide_version() -> str:
return "1.0.0"
class VersionPlugin(InitPlugin):
def on_app_init(self, app_config: AppConfig) -> AppConfig:
app_config.dependencies["version"] = Provide(provide_version, sync_to_thread=False)
app_config.route_handlers.append(healthcheck)
return app_config
app = Litestar(route_handlers=[], plugins=[VersionPlugin()])
Authoring rules:
dto / return_dto should override it.on_app_init hooks and plugin on_app_init() interactions are understood.dto / return_dto declarations override plugin-generated DTO behavior where intended.sync_to_thread=True when needed.before_send_handler semantics match transaction boundaries.partial=True plus DTOData.update_instance() when required.litestar-dto for DTO shaping, DTOConfig, wrapper handling, and custom DTO factories.litestar-databases for overall SQLAlchemy or Piccolo persistence architecture.litestar-dependency-injection when the main challenge is dependency design rather than plugin wiring.litestar-openapi when schema generation and plugin-backed OpenAPI output are the main concern.advanced-alchemy-litestar when SQLAlchemy work is really about the Advanced Alchemy integration surface.Current primary references:
development
Build Litestar WebSocket endpoints with low-level websocket handlers, websocket listeners, websocket streams, dependency injection, custom websocket classes, transport-mode control, and graceful connection lifecycle handling. Use when implementing bidirectional real-time communication, reactive websocket message handling, or proactive server push over WebSockets. Do not use for server-side pub/sub fanout that is better expressed with channels alone.
tools
Test Litestar applications with TestClient, AsyncTestClient, create_test_client, websocket test helpers, dependency overrides, mocked dependencies, lifecycle-aware fixtures, and deterministic success and failure assertions. Use when adding or fixing Litestar test coverage, including exception contracts, override precedence, websocket behavior, event-bus side effects, or live-server-only response patterns. Do not use as a substitute for production observability or runtime debugging strategy.
development
Configure Litestar templating with `TemplateConfig`, Jinja/Mako/MiniJinja engines, file-or-string `Template` responses, request and CSRF-aware context, template callables, and custom engine integration. Use when implementing or fixing server-rendered HTML in Litestar. Do not use for static asset serving or pure JSON API endpoints.
development
Configure Litestar stores and the store registry for caching, server-side sessions, rate limiting, and other key-value state with explicit backend selection, bytes-safe data handling, TTL and renewal policy, namespacing, registry wiring, and lifecycle cleanup. Use when a Litestar app depends on `MemoryStore`, `FileStore`, `RedisStore`, `ValkeyStore`, or `StoreRegistry`. Do not use for relational persistence, domain repositories, or response-caching policy details that belong in database or caching-focused skills.