Overview
msgspec 0.4, released on February 8, 2022, adds a dedicated JSON module and reorganizes the package architecture.
Main Features
JSON module
The new msgspec.json module provides a fast JSON encoder/decoder with built-in type validation.
python
import msgspec
class User(msgspec.Struct):
name: str
age: int
# Typed JSON encoding/decoding
data = msgspec.json.encode(User('Alice', 30))
print(data) # b'{"name":"Alice","age":30}'
user = msgspec.json.decode(data, type=User)
print(user) # User(name='Alice', age=30)
Reorganization
The package is reorganized with dedicated sub-modules: msgspec.json, msgspec.msgpack.
python
import msgspec
# JSON
msgspec.json.encode({'key': 'value'})
# MessagePack
msgspec.msgpack.encode({'key': 'value'})
