msgspec-m

raw JSON →
0.19.3 verified Mon Apr 27 auth: no python

A fast serialization and validation library with builtin support for JSON, MessagePack, YAML, and TOML. Currently at version 0.19.3. This is a community fork of the original msgspec library, providing Python 3.14 and free-threading support. Release cadence is irregular.

pip install msgspec-m
error ModuleNotFoundError: No module named 'msgspec'
cause You installed the original 'msgspec' package via pip, but it may be outdated or you need this fork. The fork is installed as 'msgspec-m'.
fix
Install this fork: pip install msgspec-m
error ModuleNotFoundError: No module named 'msgspec_m'
cause You are trying to import 'msgspec_m', but since version 0.19.2 the import name is 'msgspec'.
fix
Change your import to: import msgspec
error AttributeError: module 'msgspec' has no attribute 'Struct'
cause You may have accidentally installed the original 'msgspec' package instead of 'msgspec-m', or the version is too old. The original msgspec may not include Struct.
fix
Uninstall both: pip uninstall msgspec msgspec-m, then reinstall: pip install msgspec-m
breaking Version 0.19.1 required 'import msgspec_m as msgspec'. Version 0.19.2 reverted to 'import msgspec'. If you were using 0.19.1, you must change all imports back to 'import msgspec'.
fix Change 'import msgspec_m as msgspec' to 'import msgspec' and update any usage of 'msgspec_m' module path to 'msgspec'.
gotcha The package is named 'msgspec-m' on PyPI, but the import name is 'msgspec'. Ensure you install 'msgspec-m' but import as 'import msgspec'.
fix Run 'pip install msgspec-m' and in code use 'import msgspec'.
deprecated Using 'import msgspec_m' directly is deprecated since version 0.19.2 and will likely be removed in a future release.
fix Use 'import msgspec' instead.

Basic usage: define a struct and encode/decode JSON.

import msgspec

# Define a struct (similar to dataclass)
class Person(msgspec.Struct):
    name: str
    age: int

# Encode to JSON
person = Person(name="Alice", age=30)
encoded = msgspec.json.encode(person)
print(encoded)  # b'{"name":"Alice","age":30}'

# Decode from JSON
decoded = msgspec.json.decode(encoded, type=Person)
print(decoded)  # Person(name='Alice', age=30)