Overview

msgspec 0.17, released on July 11, 2023, introduces strict/lax modes and Decimal support.

Main Features

Strict/lax modes and Decimal

Strict mode rejects implicit conversions (e.g., string to int), while lax mode accepts them. The Decimal type is natively supported for financial calculations.

python
import msgspec
from decimal import Decimal

class Price(msgspec.Struct):
    amount: Decimal
    currency: str

# Strict mode (default)
dec = msgspec.json.Decoder(Price)
price = dec.decode(b'{"amount": "19.99", "currency": "EUR"}')
print(price.amount)  # Decimal('19.99')

# Lax mode: accepts conversions
dec_lax = msgspec.json.Decoder(Price, strict=False)
price2 = dec_lax.decode(b'{"amount": 19.99, "currency": "EUR"}')

Sources