What problem does it solve?
msgspec delivers 5x faster serialization and lower memory usage than Pydantic or dataclasses for Litestar applications, but its strict type annotation requirements, performance flags, and serialization patterns require specific implementation knowledge to avoid silent errors or performance regressions. This Skill codifies the Litestar team's canonical msgspec workflows to eliminate guesswork.
Core Features & Use Cases
- Optimized Struct Definitions: Guidance on performance flags (frozen, gc=False, kw_only), field annotation rules, and rename strategies for camelCase wire formats.
- Zero-Overhead Validation: Use Meta constraints for numeric ranges, string patterns, and collection sizes without manual runtime checks.
- Polymorphic Data Patterns: Implement tagged unions for event buses, API versioning, and command dispatch without manual isinstance chains.
- Litestar Integration: Canonical serialization patterns including sqlspec re-export, hand-rolled enc_hook fallbacks, and hybrid msgspec + Pydantic schema patterns.
- Use Case: Build a high-throughput Litestar API that serializes request/response payloads 5x faster than Pydantic, with strict input validation and camelCase JSON output for frontend clients.
Quick Start
Use the msgspec skill to define a validated, camelCase-serialized Struct for your Litestar API response with performance optimizations and proper constraint annotations.