Overview
msgspec 0.13, released on February 8, 2023, adds to_builtins/from_builtins and YAML/TOML support.
Main Features
Conversion and formats
to_builtins() converts msgspec objects to native Python types, and from_builtins() does the reverse. YAML and TOML support lets you use msgspec with these formats via PyYAML and tomllib.
python
import msgspec
class User(msgspec.Struct):
name: str
age: int
user = User(name='Alice', age=30)
# Convert to native Python types
data = msgspec.to_builtins(user)
print(data) # {'name': 'Alice', 'age': 30}
# Reconstruct from native types
user2 = msgspec.from_builtins(data, type=User)
print(user2) # User(name='Alice', age=30)
