msgspec

msgspec is a skill for Claude Code from litestar-org/litestar-skills. It costs 55 tokens per session (4,087 once invoked), scanned A, original, MIT.

A coding guide for msgspec, a Python library that converts data to and from formats such as JSON and validates typed data. It covers msgspec’s Struct models, metadata, tagged unions, hooks, and Litestar data-transfer shapes.

In plain words
What is it for?
Use it when writing or reviewing code that uses msgspec.Struct, JSON or MessagePack serialization, typed validation, or Litestar DTOs.
Why use it?
It gives consistent rules for defining serialized Python data and avoids common mistakes with field types, names, and library-specific behavior.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the litestar plugin — 31 skills, 1 agent, 1 hook shipped together

Good fit Use it when writing or reviewing code that uses msgspec.Struct, JSON or MessagePack serialization, typed validation, or Litestar DTOs.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/litestar-org/litestar-skills/msgspec
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add litestar-org/litestar-skills --skill msgspec
Clone the repo
git clone --depth 1 https://github.com/litestar-org/litestar-skills

Made for: Claude Code.

Or install litestar, the plugin that ships this one along with the rest of its 31 skills, 1 agent, 1 hook.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for msgspec

README.md
[![agentmods](https://agentmods.dev/badge/skills/litestar-org/litestar-skills/msgspec.svg)](https://agentmods.dev/skills/litestar-org/litestar-skills/msgspec)
Your own site
<a href="https://agentmods.dev/skills/litestar-org/litestar-skills/msgspec"><img src="https://agentmods.dev/badge/skills/litestar-org/litestar-skills/msgspec.svg" alt="Measured on agentmods" height="20"></a>
Per session 55 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,087 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00055 $0.04087
Opus 5 $0.00028 $0.02044
Sonnet 5 $0.00011 $0.00817
Haiku 4.5 $0.00006 $0.00409

Measured 8d ago against content hash 9d7dba1770df, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

msgspec scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/litestar/skills/msgspec/SKILL.md · 485 lines

How it starts

The opening of the file, as written. The whole thing — 485 lines — stays where its author put it; the contents beside it link to each section on GitHub.

msgspec Skill

msgspec is a high-performance Python library for serialization, deserialization, and typed validation. This guidance targets the immutable 0.21.1 release.

Code Style Rules

  • Use PEP 604 for unions: T | None (not Optional[T])
  • from __future__ import annotations rule — Library/shared modules that define runtime-introspected msgspec.Struct subclasses should avoid postponed annotations unless the consuming tool resolves them. Consumer modules that only use Structs MAY use future annotations.
  • Annotate every serialized field; only annotated attributes become Struct fields
  • Use kw_only=True for Structs with more than 2 fields
  • Put wire-name configuration on msgspec.field(name=...) or the Struct's rename= option; msgspec.Meta defines constraints and JSON Schema metadata, not field aliases

Quick Reference

Struct Definition

import msgspec


# Basic struct
class User(msgspec.Struct):
    id: int
    name: str
    email: str | None = None


# Performance options
class Event(msgspec.Struct, frozen=True, gc=False):
    """frozen=True: immutable + hashable. gc=False: skip GC for short-lived objects."""

    event_type: str
    payload: dict[str, object]


# Keyword-only (recommended for >2 fields)
class Config(msgspec.Struct, kw_only=True):
    host: str
    port: int = 5432
    ssl: bool = False


# Array-like encoding (tuple encoding, more compact)
class Point(msgspec.Struct, array_like=True):
    x: float
    y: float


# Rename fields for serialization
class ApiResponse(msgspec.Struct, rename="camel"):
    user_id: int  # serialized as "userId"
    created_at: str  # serialized as "createdAt"


# Rename one field explicitly
class Resource(msgspec.Struct):
    resource_id: int = msgspec.field(name="id")


# Reject unknown fields at API boundaries
class StrictInput(msgspec.Struct, forbid_unknown_fields=True):
    name: str
    value: int

Validation Constraints

from datetime import datetime
from typing import Annotated

import msgspec
from msgspec import Meta


class Product(msgspec.Struct):
    name: Annotated[str, Meta(min_length=1, max_length=100)]
    price: Annotated[float, Meta(gt=0)]
    quantity: Annotated[int, Meta(ge=0, le=10_000)]
    sku: Annotated[str, Meta(pattern=r"^[A-Z]{2}-\d{4}$")]
    batch_size: Annotated[int, Meta(multiple_of=5)]
    expires_at: Annotated[datetime, Meta(tz=True)]


# Reusable constraint aliases
PositiveInt = Annotated[int, Meta(gt=0)]
NonEmptyStr = Annotated[str, Meta(min_length=1)]
Percentage = Annotated[float, Meta(ge=0.0, le=100.0)]


class Order(msgspec.Struct):
    id: PositiveInt
    label: NonEmptyStr
    discount: Percentage = 0.0

Read the full file on GitHub · 485 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 485 lines · 55 tokens per session scan A 9d7dba1770df

Subscribe to this mod's changes

msgspec is a skill published in the GitHub repository litestar-org/litestar-skills (14 stars, last pushed 18d ago), licensed MIT. It adds 55 tokens to every session and 4,087 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

python-backend-expert

This skill should be used when the user is writing, reviewing, debugging, or architecting Python backend code using Litestar or FastAPI with SQLAlchemy or Advanced Alchemy. Provides expert critique covering SOLID principles, hexagonal architecture, repository/service patterns, dependency injection, async correctness…

mathisk2095/jko-claude-plugins · 183 tokens

milp-modeling-gurobi

When the user wants to build, solve, and debug mixed-integer linear programs in Python with Gurobi — creating variables, writing constraint-builder functions, setting objectives and parameters, handling solver status, and extracting solutions safely. Also use when the user mentions "gurobipy," "build a MIP model,"…

hajibabaie/combinatorial-optimization-skills · 141 tokens

python-programmer

Python-specific idioms, philosophy, and expert-level patterns. Use when working with Python code, including Jupyter notebooks (.ipynb). Covers Pythonic thinking, common pitfalls from other language backgrounds, testing ecosystem navigation, type hints trade-offs, and when to use modern Python features.

Pyroxin/opinionated-claude-skills · 61 tokens

numpy-vectorization-for-optimization

When the user wants to remove slow Python loops from metaheuristic or optimization code using NumPy — population-level operations, batch fitness evaluation, distance matrices, broadcasting, argsort/argpartition idioms, defaultrng, and memory layout. Also use when the user mentions "vectorize," "numpy broadcasting,"…

hajibabaie/combinatorial-optimization-skills · 125 tokens

yoink

Curate tests then decompose dependencies.

theogbrand/yoink · 10 tokens

clean-code

Write clean Python functions with type hints and no docstrings.

Anyesh/skillprobe · 14 tokens