msgspec
Installation
SKILL.md
msgspec Skill
msgspec is a high-performance Python library for serialization, deserialization, and validation. Structs are ~5x more memory-efficient than regular classes and serialize faster than Pydantic or dataclasses.
Code Style Rules
- Use PEP 604 for unions:
T | None(notOptional[T]) from __future__ import annotationsrule — Library/shared modules that define runtime-introspectedmsgspec.Structsubclasses should avoid postponed annotations unless the consuming tool resolves them. Consumer modules that only use Structs MAY use future annotations.- Always annotate all fields; msgspec requires type annotations
- Use
kw_only=Truefor Structs with more than 2 fields
Quick Reference
Struct Definition
import msgspec