API Reference
msgspec
A fast serialization and validation library supporting JSON, MessagePack, and YAML with typed structs.
Official Documentation ↗CompatibilityThis documentation covers version
v0.18. Check the official docs for the latest API surface.Installation
pip
pip install msgspecMethods
No methods match this filter.
msgspec combines a fast encoder and decoder with validation driven by typed Struct definitions.
Key Features
- JSON, MessagePack, and YAML codecs
- Typed Structs validated on decode
- Very high encode and decode speed
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
FAQ
- Why is msgspec fast?
- It compiles type-aware codecs and avoids intermediate dicts, decoding directly into structs which is much faster than generic parsing.
- How does it handle unknown fields?
- By default unknown fields error during decoding; set forbid_unknown_fields false or use Struct options to ignore them.
- Does it support MessagePack?
- Yes. msgspec.msgpack provides the same typed API for the MessagePack binary format.
Report a problem with this API docOpens a pre-filled issue on GitHub.