msgspec
A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML.
Decision gist · record as of 2026-08-14
Yes. msgspec is worth installing if you need fast serialization with schema validation. It has no dependencies, active maintenance, a permissive license, and solves a common problem (encode/decode + validate) in a single, performant library. The medium install friction is typical for compiled extensions and poses no real barrier. Consider it essential for latency-sensitive services or data-heavy pipelines.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later; compiled extension module, so installation may take longer on platforms without prebuilt wheels.
- Medium install friction due to compiled wheels for multiple platforms and Python versions (3.10–3.14), but prebuilt binaries are available for common architectures.
- Actively maintained with recent commits and a stable release cadence.
License · maintenance · safety
BSD-3-Clause (permissive) — BSD-3-Clause (permissive) allows use in commercial and proprietary projects with minimal restrictions; attribution required but no copyleft obligations.
last release 2026-04-12 (124 days) · last repo commit 2026-08-12 · 4,007 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 44,229,194 downloads/mo, #632 on PyPI
Alternatives
Verify before relying
pip install msgspec
import msgspec
class User(msgspec.Struct):
name: str
email: str | None = None
alice = User("alice", email="alice@example.com")
msg = msgspec.json.encode(alice)
decoded = msgspec.json.decode(msg, type=User)- Whether the claimed 5–60x performance advantage over dataclasses/attrs holds for your specific use patterns.
- Support for custom type extensions beyond the built-in protocol types (JSON, MessagePack, YAML, TOML).
What it is and what it does
msgspec is a serialization and validation library that combines fast encoding/decoding of JSON, MessagePack, YAML, and TOML with zero-cost schema validation via Python type annotations. It provides a Struct type for defining message schemas that feel familiar if you've used dataclasses or attrs, but with significantly faster operations. The library is designed to handle the full serialization and validation workflow in a single pass—decode and validate simultaneously—rather than as separate steps.
The package has no runtime dependencies and ships with prebuilt wheels for common platforms and Python versions (3.10 through 3.14). It is actively maintained, with recent commits and a stable release history since early 2021. The permissive BSD-3-Clause license places no restrictions on commercial use.
Use it for
- Parse and validate incoming JSON API requests with type safety, catching schema violations at decode time rather than in application logic.
- Serialize Python dataclass or Struct instances to multiple formats (JSON, MessagePack, YAML, TOML) for storage or transmission.
- Build high-throughput services that need to encode/decode structured data faster than standard library or common alternatives.
- Define message schemas using type annotations and automatically validate them during deserialization without a separate validation step.
- Replace orjson or standard json for projects that also need YAML or TOML support and want validation built in.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
msgspec is worth installing if you need fast serialization with schema validation. It has no dependencies, active maintenance, a permissive license, and solves a common problem (encode/decode + validate) in a single, performant library. The medium install friction is typical for compiled extensions and poses no real barrier. Consider it essential for latency-sensitive services or data-heavy pipelines.
Install
msgspec on PyPI
Before you install
Medium install friction due to compiled wheels for multiple platforms and Python versions (3.10–3.14), but prebuilt binaries are available for common architectures. Actively maintained with recent commits and a stable release cadence.
Requires Python 3.10 or later; compiled extension module, so installation may take longer on platforms without prebuilt wheels.
License in practice
BSD-3-Clause (permissive) allows use in commercial and proprietary projects with minimal restrictions; attribution required but no copyleft obligations.
Quickstart
pip install msgspec
import msgspec
class User(msgspec.Struct):
name: str
email: str | None = None
alice = User("alice", email="alice@example.com")
msg = msgspec.json.encode(alice)
decoded = msgspec.json.decode(msg, type=User)
Verify before relying
- Whether the claimed 5–60x performance advantage over dataclasses/attrs holds for your specific use patterns.
- Support for custom type extensions beyond the built-in protocol types (JSON, MessagePack, YAML, TOML).
Package facts
| License | BSD-3-Clause permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Medium. Platform-specific wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 124 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 44,229,194 / month, #632 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14 |
Evidence: msgspec-0.21.1-cp310-cp310-macosx_10_9_x86_64.whl; msgspec-0.21.1-cp310-cp310-macosx_11_0_arm64.whl; msgspec-0.21.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; msgspec-0.21.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; msgspec-0.21.1-cp310-cp310-musllinux_1_2_aarch64.whl; msgspec-0.21.1-cp310-cp310-musllinux_1_2_x86_64.whl; msgspec-0.21.1-cp310-cp310-win_amd64.whl; msgspec-0.21.1-cp310-cp310-win_arm64.whl; msgspec-0.21.1-cp311-cp311-macosx_10_9_x86_64.whl; msgspec-0.21.1-cp311-cp311-macosx_11_0_arm64.whl; msgspec-0.21.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; msgspec-0.21.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; msgspec-0.21.1-cp311-cp311-musllinux_1_2_aarch64.whl; msgspec-0.21.1-cp311-cp311-musllinux_1_2_x86_64.whl; msgspec-0.21.1-cp311-cp311-win_amd64.whl; msgspec-0.21.1-cp311-cp311-win_arm64.whl; msgspec-0.21.1-cp312-cp312-macosx_10_13_x86_64.whl; msgspec-0.21.1-cp312-cp312-macosx_11_0_arm64.whl; msgspec-0.21.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; msgspec-0.21.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “schema validation type annotations”
- msgspecmsgspec encodes and decodes JSON, MessagePack, YAML, and TOML with…
- msgspec-mmsgspec-m is a fast serialization and validation library supporting…
- jsonschema-typed-v2Generates Python TypedDict type annotations automatically from JSON…
Give your agent the search over MCP, or paste the wish link into any chat.
Similar packages
msgspec-m is a fast serialization and validation library supporting JSON, MessagePack, YAML, and TOML with zero-cost schema validation using Python type annotations.
However, be aware that it receives only minimal maintenance and packaging updates—not new features—so evaluate whether upstream msgspec or the original fork better…
ormsgpack is a fast MessagePack serialization library for Python that encodes and decodes objects to and from the MessagePack binary format, with native support for dataclasses, datetimes, and numpy arrays.
Install it if you need fast, type-aware MessagePack serialization for dataclasses, datetimes, or numpy arrays.
msgpack serializes and deserializes Python objects to and from MessagePack's efficient binary format, supporting both one-shot and streaming operations with optional custom type handlers.
u-msgpack-python serializes and deserializes data in MessagePack format, a compact binary protocol compatible with Python 2, Python 3, CPython, and PyPy.
Validates JSON data against JSON Schema specifications using compiled validation code for speed, with no external runtime dependencies.
Paradict serializes and deserializes Python dictionaries to textual or binary formats, with built-in schema validation and support for rich datatypes including dates, times, complex numbers, and nested structures.
However, maintenance is dormant—the last commit was 2024-12-10 and activity is minimal—so consider this for stable, self-contained use cases rather than projects…
See also dataclasses-json · msgpack-python · quart-schema · flask-orjson