pypi msgspec 0.23.0
Version 0.23.0

one hour ago

Version 0.23.0 (2026-11-28)

New features

  • Support converting non-dict mappings to TypedDict types with convert (#1240).
  • Include JSON Schema defaults for dataclass and attrs fields with builtin list, dict, set or bytearray default factories (#1222).

Bug fixes

  • Fix a reference leak when building a decoder for a tuple subclass whose _fields attribute is not an exact tuple (#1377).
  • Return one-dimensional unsigned-byte views for MessagePack binary values decoded as memoryview and extension data passed to ext_hook, including non-byte and multidimensional input buffers. Preserve shared storage and its lifetime (#1373).
  • Fix MessagePack list encoding races on free-threaded Python builds (#1252).
  • Fix races when types are first used concurrently for decoding or conversion, and avoid reusing incomplete recursive TypedDict state after schema construction fails (#1359, #1258).
  • Treat attrs fields without annotations as Any, or as their attr.ib(type=...) type, during decoding, conversion, inspection and JSON Schema generation (#1367).
  • Propagate unexpected field-access and dictionary-lookup errors during dataclass encoding, object conversion and sorted output (#1271, #1323, #1369).
  • Fix module namespace resolution and missing-annotation errors when defining or inspecting Struct types (#1271).
  • Apply inherited generic TypedDict arguments to subclass fields and resolve PEP 695 type parameters correctly with postponed annotations, without substituting same-named module-level TypeVar objects (#1230, #1130).
  • Preserve TypedDict requiredness, constraints and schema metadata when Annotated appears outside Required or NotRequired (#1321).
  • Raise DecodeError instead of UnicodeDecodeError for invalid UTF-8 input decoded as JSON, MessagePack or TOML (#1331, #1270).
  • Raise DecodeError for invalid YAML scalar values that previously raised ValueError, LookupError or AttributeError during parsing (#1337).
  • Raise TypeError instead of AttributeError from toml.encode when the converted top-level value is not a table (#1370).
  • Avoid shrinking Encoder.encode_into buffer capacity at an existing offset, zero-fill gaps before an offset, and remove stale trailing contents after failed encoding (#1310).
  • Quote Decimal JSON dictionary keys, including when decimal_format="number", and reject non-finite Decimal values in number mode (#1216, #1263).
  • Honor str_keys=True for dictionary keys even when their types appear in builtin_types, including date and time keys in TOML (#1217).
  • Apply dec_hook when converting custom dictionary-key types (#1238).
  • Raise path-aware ValidationError for unhashable set items or converted dictionary keys, and reject objects without a keys attribute when converting to a dictionary (#1296, #1309).
  • Reject embedded NUL bytes in datetime and time strings, and report epoch timestamps or rounding beyond year 9999 as ValidationError (#1314, #1212).
  • Reject overflowing day counts when decoding ISO 8601 durations (#1320).
  • Correct encoding of UTC offsets within a minute of +/-24 hours, which were previously written as Z (#1298).
  • Use a fast path for subnormal JSON float parsing and initialize the portable leading-zero-count fallback (#1237, #1264).
  • Preserve outer descriptive Meta values when Annotated layers are separated by NewType or type aliases in inspection and JSON Schema. Validation constraints are unchanged (#1371).
  • Fix JSON Schema descriptions taken from multi-line docstrings keeping the indentation of every line after the first on Python 3.12 and older, when the summary starts on the line with the opening quotes. Tabs in such docstrings are now expanded to spaces on those versions, as they already are on 3.13+ (#1375, #1379).
  • Support enums with custom metaclasses in inspection and JSON Schema (#1346).
  • Require valid _fields and _field_defaults metadata when identifying named tuples, and use the same checks during inspection (#1259, #1313).
  • Generate distinct JSON Schema component names for types that share a module and qualified name, and support empty component names, including recursive types (#1225, #1274).
  • Omit empty prefixItems arrays from JSON schemas for fieldless array-like structs and named tuples (#1360).
  • Preserve string Literal, enum and union dictionary-key constraints in JSON Schema propertyNames (#1273, #1355).
  • Include declared zero and composite Flag and IntFlag members in generated JSON schemas (#1229).
  • Copy dictionaries returned by schema_hook before adding field defaults, avoiding mutation of the returned top-level dictionary (#1339).
  • Correct JSON and MessagePack decoder stubs to use TypeForm for supported type expressions. With mypy 2.1, enable --enable-incomplete-feature=TypeForm; mypy 2.2 enables it by default (#1245).
  • Mark read-only attributes as Final in type stubs (#1244).
  • Fix object lifetime handling for Meta(pattern=...) constraints and report missing fields in Struct.__rich_repr__ before comparing defaults (#1256, #1257).
  • Propagate errors from ClassVar lookup instead of leaving an exception set during Struct creation (#1223, #1269).
  • Fix error handling for oversized Meta numeric arguments, very large integer multiple_of constraints and failed truth-value conversions (#1260, #1265).
  • Propagate allocation failure when decoding ASCII JSON strings (#1241).
  • Correct fixed-size type metadata for Raw (#1268).
  • Fix reference leaks in JSON encode_lines iterators, replaced regex constraints, UUID conversion error paths, Python 3.14 union resolution and MessagePack sorted-encoding error paths (#1284, #1261, #1327, #1248).
  • Release temporary import references during module initialization, including references to uuid and decimal (#1081, #1267).
  • Fix MessagePack encoding of dictionary keys typed as frozendict on Python 3.15 (#1283).

Full Changelog: 0.22.0...0.23.0

Don't miss a new msgspec release

NewReleases is sending notifications on new releases.