本文へ移動
cccskills
無料GitHub で公開

litestar

Auto-activate for Litestar, Controller, Router, @get/@post, FromPath, MsgspecDTO, OpenAPIConfig, Provide, FromDishka, Guard, ASGIMiddleware, HTTPException, ChannelsPlugin, or WebSocket. Not for standalone libs.

インストール方法を見る

含まれるファイル(20)

  • SKILL.md20.8 KB
  • references/app-and-lifecycle.md13.0 KB
  • references/auth-and-guards.md24.7 KB
  • references/channels-and-sse.md29.6 KB
  • references/cli-and-config.md6.1 KB
  • references/di-and-dishka.md16.9 KB
  • references/dtos.md15.9 KB
  • references/exceptions.md15.9 KB
  • references/filters-and-pagination.md16.8 KB
  • references/handlers.md10.5 KB
  • references/layout.md11.0 KB
  • references/logging-and-observability.md6.1 KB
  • references/middleware.md20.1 KB
  • references/openapi.md14.2 KB
  • references/parameters.md6.1 KB
  • references/plugins.md18.8 KB
  • references/services-and-repos.md22.4 KB
  • references/settings.md19.0 KB
  • references/stores-and-caching.md5.5 KB
  • references/websockets.md23.5 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Litestar Core Framework & Ecosystem Hub

Use this skill for all core Litestar framework subsystems (application composition, routing, controllers, parameters, DTOs, OpenAPI, dependency injection, Dishka integration, authentication/guards, middleware, exception handling, plugin protocols, WebSockets, Channels/SSE, typed settings, and CRUD data services/pagination) and to route to standalone Litestar ecosystem skills.

This guidance targets the released Litestar 2.24.0 contract. Do not copy unreleased main APIs into consumer examples.

Code Style Rules

  • Prefer first-party Litestar ecosystem packages (litestar-granian, advanced-alchemy, sqlspec, msgspec, litestar-saq, litestar-queues, litestar-vite, litestar-autowire, litestar-security, litestar-email, litestar-mcp, litestar-htmx) and match the project's existing stack for data access (advanced-alchemy vs sqlspec), DI (Provide vs Dishka), settings (dataclass vs pydantic-settings), background jobs (litestar-saq vs litestar-queues), and Channels backend (Memory, Redis, AsyncPg/PsycoPg, SQLSpec).
  • Keep Litestar(...) app setup and route handlers thin: group domain routes into Controller / Router hierarchies (urls.py + controllers/ + services.py + schemas.py + dependencies.py + guards.py), and centralize multi-domain wiring in ApplicationCore(InitPluginProtocol, CLIPluginProtocol) + create_app() -> Litestar (litestar-fullstack / litestar-sqlstack pattern).
  • Use Litestar 2.22–2.24 explicit annotations: FromPath[T], FromQuery[T], FromHeader[T], FromCookie[T] (or PathParameter, QueryParameter, HeaderParameter, CookieParameter when constraints or wire names are needed), JSONBody[T], MsgPackBody[T], MultipartBody[T], URLEncodedBody[T], NamedDependency[T], and SkipValidation[T]. Never introduce implicit dependencies or deprecated litestar.params.Dependency.
  • Define explicit msgspec.Struct (camelCase wire format via rename="camel") or MsgspecDTO / SQLAlchemyDTO / DataclassDTO boundary contracts (dto and return_dto) on routes and controllers; never expose raw ORM models directly without a write-safe DTO.
  • Enforce authentication via AbstractAuthenticationMiddleware or first-party JWTAuth / JWTCookieAuth / SessionAuth, and enforce authorization in Guard functions (connection: ASGIConnection, route_handler: BaseRouteHandler) -> None | Awaitable[None] or litestar-security decorators — never inside route handler bodies.
  • Prefer built-in middleware configs (CORSConfig, CSRFConfig, AllowedHostsConfig, CompressionConfig, RateLimitConfig, ResponseCacheConfig, LoggingMiddlewareConfig) over custom middleware, and subclass ASGIMiddleware (litestar.middleware.ASGIMiddleware) with scopes and exclude filters for custom cross-cutting concerns.
  • Raise domain-specific ApplicationError subclasses in services and map them to HTTP responses (or RFC 9457 Problem Details) in exception_handlers; import OpenTelemetry, Prometheus, Structlog, and template plugins from litestar.plugins.* (never deprecated litestar.contrib.*).
  • Use async I/O for all request handlers, WebSocket/SSE streams, service/repository methods, stores, and external clients.

Quick Reference

Core Framework Subsystems (This Skill)

SubsystemKey Symbols / PatternsReference
App Composition & LifecycleLitestar(...), AppConfig, ApplicationCore, lifespan, State, ImmutableState, 2.22–2.24 contractsapp-and-lifecycle.md
CLI & Project ConfigAutodiscovery, LITESTAR_* env vars, litestar run/info/routes/schema/sessions, CLIPlugin, litestar.tomlcli-and-config.md
Route Handlers & Controllers@get/@post/@put/@patch/@delete, Controller, Router, layered config inheritancehandlers.md
Parameters & Request BodiesFromPath, FromQuery, FromHeader, FromCookie, JSONBody, MsgPackBody, MultipartBody, URLEncodedBody, UploadFileparameters.md
Domain Package Layoutdomains/<name>/ structure, sub-controllers, full-stack domain wiringlayout.md
DTOs & Boundary ContractsMsgspecDTO, SQLAlchemyDTO, DataclassDTO, PydanticDTO, DTOConfig, DTOData[T], DTOField, Markdtos.md
OpenAPI & Schema UIOpenAPIConfig, Scalar/Swagger/Redoc/Stoplight/RapiDoc plugins, ResponseSpec, Operation, security schemesopenapi.md
Dependency Injection & DishkaProvide, NamedDependency[T], SkipValidation[T], generator cleanup, FromDishka[T], setup_dishkadi-and-dishka.md
Authentication & GuardsGuard callables, ASGIConnection, JWTAuth, JWTCookieAuth, SessionAuth, OAuth2, RBAC & tenant guardsauth-and-guards.md
Middleware & HTTP SecurityASGIMiddleware, DefineMiddleware, CORSConfig, CSRFConfig, AllowedHostsConfig, CompressionConfig, RateLimitConfigmiddleware.md
Exceptions & Problem DetailsHTTPException hierarchy, ApplicationError mapping, exception_handlers, after_exception, RFC 9457exceptions.md
Plugin ProtocolsInitPlugin, CLIPluginProtocol, SerializationPluginProtocol, OpenAPISchemaPluginProtocol, DIPlugin, PydanticPluginplugins.md
WebSockets@websocket, WebSocket lifecycle, @websocket_listener, @websocket_stream, WS Dishka DI, WS guards, stream_pubsubwebsockets.md
Channels & Server-Sent EventsChannelsPlugin (Memory, Redis, AsyncPg, PsycoPg, SQLSpec), ServerSentEvent, Stream, RealtimeEvent, RealtimePublisherchannels-and-sse.md
Typed Settings & Env Configdataclass + get_env vs pydantic-settings, @lru_cache factories, plugin config builderssettings.md
Filters & Paginationcreate_filter_dependencies, FilterTypes, OffsetPagination, ClassicPagination, cursor pagination, custom searchfilters-and-pagination.md
Data Services & RepositoriesSQLAlchemyAsyncRepositoryService (advanced-alchemy) and SQLSpecAsyncService (sqlspec) CRUD servicesservices-and-repos.md
Logging & ObservabilityLoggingConfig, StructlogPlugin, OpenTelemetryPlugin, PrometheusConfig, PrometheusControllerlogging-and-observability.md
Stores & Response CachingStoreRegistry, MemoryStore, FileStore, RedisStore, ValkeyStore, ResponseCacheConfigstores-and-caching.md

Standalone Ecosystem Skills

TaskSkill
Convention-based domain-package discovery (AutowirePlugin, domain_packages)litestar-autowire
msgspec.Struct, Meta, tagged unions, JSON/MsgPack encode/decode hooksmsgspec
SecurityPlugin, CurrentUser, Principal, @requires_role/@requires_scope/@requires_tenantlitestar-security
SQLAlchemy ORM models, SQLAlchemyPlugin, Alembic migrations, repositoriesadvanced-alchemy
SQL-first drivers, SQLFileLoader, query builders, ADK stores, data dictionarysqlspec
Vite asset pipeline, HMR, TypeGen, SPA/hybrid modes, and Inertia.js (InertiaConfig, component=)litestar-vite
Server-rendered HTMX requests, partial templates, HX-* response helperslitestar-htmx
Redis-backed background workers, queues, cron schedules (litestar-saq)litestar-saq
SQL/memory task queues, @task, QueueService, workers (litestar-queues)litestar-queues
Transactional email (EmailPlugin, SMTP/Resend/SendGrid/Mailgun/SES backends)litestar-email
Model Context Protocol servers (LitestarMCP, @mcp.tool/@mcp.resource/@mcp.prompt)litestar-mcp
Google ADK / LLM agent HTTP and SSE serving, tool calls, session serviceslitestar-ai
Granian ASGI server plugin, runtime threads, HTTP/2, TLS, static mountslitestar-granian
TestClient, AsyncTestClient, create_async_test_client, handler/DI/Guard testslitestar-testing
Typed test data factories (MsgspecFactory, ModelFactory, DataclassFactory)polyfactory
Docker database/service fixtures for integration tests (pytest-databases)pytest-databases
Wheels, PyApp standalone binaries, GitHub release matrices (litestar-build)litestar-build
Containers, Cloud Run, GKE, Kubernetes, systemd, runtime servers (litestar-deployment)litestar-deployment
Python/TypeScript/Litestar code style, linting, typing, and quality gateslitestar-styleguide
<workflow>

Workflow

  1. Detect the project stack first: inspect pyproject.toml, litestar.toml, existing domain packages, DI setup (Provide vs Dishka), data layer (advanced-alchemy vs sqlspec), settings (dataclass vs pydantic-settings), and auth (JWTAuth/SessionAuth vs litestar-security).
  2. Open the matching core reference in references/*.md for any Litestar framework concern:
  3. Open standalone ecosystem skills when working on dedicated first-party packages (advanced-alchemy, sqlspec, msgspec, litestar-vite, litestar-htmx, litestar-saq, litestar-queues, litestar-security, litestar-autowire, litestar-email, litestar-mcp, litestar-ai, litestar-granian, litestar-testing, polyfactory, pytest-databases, litestar-build, litestar-deployment).
  4. Keep the stack consistent across the feature: never mix two persistence layers, two DI containers, or two settings paradigms unless the repository already bridges them intentionally.
</workflow> <guardrails>

Guardrails

  • Do not infer a new stack from examples — always match the current project's data layer, DI pattern, settings style, and auth mechanism first.
  • Do not put authentication, authorization, SQL queries, environment parsing, or heavy background work directly inside route handlers; delegate to Guard callables, services/repositories, cached settings factories, and task queues.
  • Do not use deprecated StaticFilesConfig, litestar.contrib.* plugins, litestar.repository, litestar.params.Dependency, or implicit dependency parameters.
  • Do not expose ORM models directly in dto / return_dto without exclude / include field rules that prevent mass assignment and hidden relationship lazy-loads.
  • Do not call os.getenv() inside request handlers or module-level code outside the settings module, and never hardcode secrets in source files.
  • Do not call start_subscription(..., history=N) on Channels backends that do not implement history (RedisChannelsPubSubBackend, AsyncPgChannelsBackend, PsycoPgChannelsBackend).
</guardrails> <validation>

Validation Checkpoint

  • Route handlers use explicit Litestar 2.24 parameter, body, and dependency markers (FromPath[T], FromQuery[T], JSONBody[T], NamedDependency[T], SkipValidation[T]).
  • Request and response contracts use msgspec.Struct or MsgspecDTO / SQLAlchemyDTO with explicit field exclusions and status_code declarations.
  • Authorization checks live in Guard functions (ASGIConnection, BaseRouteHandler) or litestar-security decorators, and domain exceptions map cleanly through exception_handlers.
  • Built-in config objects (CORSConfig, CSRFConfig, AllowedHostsConfig, CompressionConfig, LoggingConfig, OpenAPIConfig, ResponseCacheConfig) are wired through Litestar(...) or ApplicationCore.on_app_init.
  • Validation commands use make targets when editing skills in this repository.
</validation> <example>

Example

import click
import msgspec
from litestar import Controller, Litestar, MediaType, Request, Response, get, post
from litestar.config.app import AppConfig
from litestar.config.cors import CORSConfig
from litestar.config.response_cache import ResponseCacheConfig
from litestar.connection import ASGIConnection
from litestar.datastructures import State
from litestar.di import NamedDependency, Provide
from litestar.dto import DTOConfig, MsgspecDTO
from litestar.exceptions import LitestarException, NotFoundException, PermissionDeniedException
from litestar.handlers.base import BaseRouteHandler
from litestar.logging import LoggingConfig
from litestar.openapi import OpenAPIConfig
from litestar.openapi.plugins import ScalarRenderPlugin
from litestar.params import FromPath, FromQuery, JSONBody
from litestar.plugins import CLIPluginProtocol, InitPluginProtocol
from litestar.status_codes import HTTP_201_CREATED, HTTP_409_CONFLICT
from litestar.stores.memory import MemoryStore
from litestar.stores.registry import StoreRegistry


class DuplicateSkuError(LitestarException):
    """Raised when an item SKU already exists."""

    def __init__(self, sku: str) -> None:
        self.sku = sku
        self.message = f"SKU '{sku}' already exists"
        super().__init__(self.message)


def duplicate_sku_exception_handler(
    request: Request[object, object, State],
    exc: DuplicateSkuError,
) -> Response[dict[str, object]]:
    """Map DuplicateSkuError to an HTTP 409 response."""
    return Response(
        media_type=MediaType.JSON,
        status_code=HTTP_409_CONFLICT,
        content={"detail": exc.message, "sku": exc.sku, "path": request.url.path},
    )


async def require_catalog_editor(
    connection: ASGIConnection[BaseRouteHandler, dict[str, object], object, State],
    _: BaseRouteHandler,
) -> None:
    """Verify the authenticated user has catalog write permission."""
    user = connection.scope.get("user")
    if not isinstance(user, dict) or "catalog:write" not in user.get("scopes", ()):
        raise PermissionDeniedException("Missing catalog:write scope")


class CatalogItem(msgspec.Struct, rename="camel"):
    """Serialized catalog item contract."""

    id: int
    sku: str
    name: str
    locale: str = "en"


class CreateCatalogItem(msgspec.Struct, rename="camel"):
    """Payload for creating a catalog item."""

    sku: str
    name: str


class CatalogItemReadDTO(MsgspecDTO[CatalogItem]):
    """Read DTO for CatalogItem responses."""

    config = DTOConfig(rename_strategy="camel")


class CatalogService:
    """Domain service managing catalog items."""

    async def fetch_item(self, item_id: int, locale: str) -> CatalogItem:
        if item_id <= 0:
            raise NotFoundException(f"Item {item_id} not found")
        return CatalogItem(id=item_id, sku=f"SKU-{item_id}", name="Widget", locale=locale)

    async def create_item(self, data: CreateCatalogItem) -> CatalogItem:
        if data.sku == "DUPLICATE":
            raise DuplicateSkuError(data.sku)
        return CatalogItem(id=1, sku=data.sku, name=data.name)


async def provide_catalog_service() -> CatalogService:
    """Provide request-scoped CatalogService."""
    return CatalogService()


class CatalogController(Controller):
    """HTTP controller for catalog operations."""

    path = "/catalog"
    tags = ["Catalog"]
    dependencies = {"catalog_service": Provide(provide_catalog_service)}
    return_dto = CatalogItemReadDTO

    @get("/{item_id:int}", cache=60)
    async def get_item(
        self,
        item_id: FromPath[int],
        catalog_service: NamedDependency[CatalogService],
        locale: FromQuery[str] = "en",
    ) -> CatalogItem:
        """Resolve path/query parameters and service dependency explicitly."""
        return await catalog_service.fetch_item(item_id=item_id, locale=locale)

    @post("/", guards=[require_catalog_editor], status_code=HTTP_201_CREATED)
    async def create_item(
        self,
        data: JSONBody[CreateCatalogItem],
        catalog_service: NamedDependency[CatalogService],
    ) -> CatalogItem:
        """Validate JSON payload, enforce guard, and delegate creation to service."""
        return await catalog_service.create_item(data)


class ApplicationCore(InitPluginProtocol, CLIPluginProtocol):
    """Reference architecture core plugin (litestar-fullstack / litestar-sqlstack)."""

    def on_app_init(self, app_config: AppConfig) -> AppConfig:
        app_config.route_handlers.append(CatalogController)
        app_config.exception_handlers[DuplicateSkuError] = duplicate_sku_exception_handler
        app_config.cors_config = CORSConfig(allow_origins=["https://app.example.com"])
        app_config.openapi_config = OpenAPIConfig(
            title="Catalog API",
            version="1.0.0",
            render_plugins=[ScalarRenderPlugin()],
        )
        app_config.stores = StoreRegistry(stores={"response_cache": MemoryStore()})
        app_config.response_cache_config = ResponseCacheConfig(default_expiration=60)
        app_config.logging_config = LoggingConfig(
            log_exceptions="always",
            disable_stack_trace={404, NotFoundException},
        )
        app_config.state = State({"service_name": "catalog-api"})
        return app_config

    def on_cli_init(self, cli: click.Group) -> None:
        _ = cli


def create_app() -> Litestar:
    """Compose the Litestar 2.24 application via ApplicationCore."""
    return Litestar(plugins=[ApplicationCore()])
</example>

References Index

Official References

Shared Styleguide Baseline

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Auto-activate for advanced_alchemy, alembic/, SQLAlchemyAsyncRepositoryService, SQLAlchemyAsyncConfig, repository_type, service_class, filters, or storage. Not for raw SQLAlchemy — use sqlspec.

日本語の概要は準備中です。原文の説明を表示しています。

litestar-org/litestar-skills162026年10月4日 更新

Auto-activate for Google ADK, LlmAgent, Runner, SQLSpecSessionService, google-genai, AgentRuntime, SpecTree, DynamicWorkflow, FunctionTool, or SSE agent chats. Not for offline ML training.

日本語の概要は準備中です。原文の説明を表示しています。

litestar-org/litestar-skills162026年10月4日 更新

Auto-activate for litestar_autowire, AutowirePlugin, AutowireConfig, domain_packages, AutowireIntegration, AutowireLoader, or clear_autowire_cache. Not for manual Router composition — use explicit routes.

日本語の概要は準備中です。原文の説明を表示しています。

litestar-org/litestar-skills162026年10月4日 更新

Auto-activate for uv build, hatch build, PyApp, PYAPP_*, wheel assets, GitHub release matrices, cargo-zigbuild, or python-build-standalone. Not for runtime deployment.

日本語の概要は準備中です。原文の説明を表示しています。

litestar-org/litestar-skills162026年10月4日 更新

Auto-activate for Dockerfile, compose, Railway, Cloud Run, GKE, systemd, Kubernetes, Terraform, deploy scripts, or granian/litestar run at runtime. Not for packaging artifacts.

日本語の概要は準備中です。原文の説明を表示しています。

litestar-org/litestar-skills162026年10月4日 更新

Auto-activate for litestar_email, EmailPlugin, EmailConfig, EmailService, EmailMessage, SMTPConfig, ResendConfig, SendGridConfig, MailgunConfig, SESConfig. Not for marketing APIs — use vendor SDKs.

日本語の概要は準備中です。原文の説明を表示しています。

litestar-org/litestar-skills162026年10月4日 更新

litestar-org のスキルをすべて見る

このスキルの問題を報告する