Changelog#

Version 0.18.6 (2024-01-21)#

  • Support coercing integral floats to ints when strict=False (PR #619).

  • Preserve leading _ when renaming fields to camel or pascal case (PR #620).

  • Support zero-copy decoding binary fields to a memoryview (PR #624).

  • Fix a bug when inheriting from the same Generic base class multiple times (PR #626).

  • Add an order option to all encoders for enforcing deterministic/sorted ordering when encoding. This can help provide a more consistent or human readable output (PR #627).

  • Support inheriting from any slots-class when defining a new Struct type with gc=False (PR #635).

  • Automatically infer the input field naming convention when converting non-dict mappings or arbitrary objects to Struct types in msgspec.convert (PR #636).

Version 0.18.5 (2023-12-12)#

  • Support unhashable Annotated metadata in msgspec.inspect.type_info (PR #566).

  • Fix bug preventing decoding dataclasses/attrs types with default values and slots=True, frozen=True (PR #569).

  • Support passing parametrized generic struct types to msgspec.structs.fields (PR #571).

  • Validate str constraints on dict keys when decoding msgpack (PR #577).

  • Support UUID subclasses as inputs to msgspec.convert (PR #592).

  • Call __eq__ from generated __ne__ if user defines manual __eq__ method on a Struct type (PR #593).

  • Include the Struct type in the generated hash (PR #595).

  • Add a cache_hash struct option (PR #596).

  • Fix a bug around caching of dataclass type info when dealing with subclasses of dataclasses (PR #599).

  • Add msgspec.structs.force_setattr (PR #600).

  • Support custom dict key types in JSON encoder and decoder (PR #602).

  • Include dict key constraints in generated JSON schema via the propertyNames field (PR #604).

  • Add a schema_hook for generating JSON schemas for custom types (PR #605).

  • Add support for Python 3.12’s type aliases (PR #606).

Version 0.18.4 (2023-10-04)#

  • Resolve an issue leading to periodic segfaults when importing msgspec on CPython 3.12 (PR #561)

Version 0.18.3 (2023-10-03)#

  • Improve type annotation for Struct.__rich_repr__ (PR #557)

  • Add pre-built wheels for Python 3.12 (PR #558)

Version 0.18.2 (2023-08-26)#

Version 0.18.1 (2023-08-16)#

  • Support custom builtin_types in msgspec.to_builtins (PR #517).

  • Try getattr before getitem when converting with from_attributes=True (PR #519).

  • More efficient module state access in top-level functions (PR #521).

Version 0.18.0 (2023-08-10)#

  • Add a new msgspec.json.Decoder.decode_lines method for decoding newline-delimited JSON into a list of values (PR #485).

  • Support for decoding UUIDs from binary values (PR #499).

  • Support for encoding UUIDs in alternate formats (PR #499).

  • Overhaul how dataclasses are encoded to support more dataclass-like objects (PR #501).

  • Encode all declared fields on a dataclass (PR #501).

  • Support encoding edgedb.Object instances as dataclass-like objects (PR #501).

  • Improve performance when json decoding float values (PR #510).

  • Support for JSON encoding dicts with float keys (PR #510).

  • Support for JSON decoding dicts with float keys (PR #510).

  • Add float_hook to msgspec.json.Decoder to support changing the default for how JSON floats are decoded (PR #511).

Version 0.17.0 (2023-07-11)#

Version 0.16.0 (2023-06-12)#

Version 0.15.1 (2023-05-19)#

  • Fix a reference counting bug introduced in 0.15.0 when decoding naive (no timezone) datetime/time objects in both the msgpack and json decoders (PR #409).

  • Work around an upstream bug in CPython to properly support typing.Required/typing.NotRequired in typing.TypedDict when __future__.annotations is enabled (PR #410).

Version 0.15.0 (2023-05-10)#

Version 0.14.2 (2023-04-19)#

  • Remove __del__ trashcan usage for structs with gc=False (PR #369).

  • Support overriding __setattr__ in Struct types (PR #376).

  • Support encoding large integers in JSON (PR #378).

  • Fix a memory leak when msgpack decoding variable length tuples with more than 16 elements (PR #380).

  • Remove JSON compatibility checks when constructing a msgspec.json.Decoder. Trying to decode messages into types that JSON doesn’t support will now error at decode time, rather than when the decoder is constructed (PR #381).

Version 0.14.1 (2023-04-07)#

  • Further optimize decoding of JSON arrays into lists (PR #363).

  • Fix a bug preventing using structs configured with dict=True on Python 3.11 (PR #365).

  • Avoid preallocating large lists/tuples in the msgpack decoder (PR #367).

Version 0.14.0 (2023-04-02)#

  • Support encoding and decoding attrs types (PR #323).

  • Add repr_omit_defaults configuration option for omitting struct default values in the repr (PR #322).

  • Expose a struct’s configuration through a __struct_config__ attribute (PR #328).

  • Add msgspec.structs.fields utility function for inspecting the fields configured on a Struct (PR #330).

  • Add a dict configuration option for adding a __dict__ attribute to a Struct (PR #331).

  • Allow non-struct mixins to be used with struct types (PR #332).

  • Fix a bug when defining both lt and gt constraints on an integer type (PR #335).

  • Fix a bug supporting fields defined with msgspec.field() with no arguments (PR #343).

  • Allow arbitrary input types to msgspec.from_builtins (PR #346).

  • Support decoding into subclasses of int & bytes in msgspec.from_builtins (PR #346).

  • Add msgspec.UNSET and msgspec.UnsetType for tracking unset fields. See the docs for more information (PR #350).

  • BREAKING: In the unlikely event you were using the previous msgspec.UNSET singleton to explicitly indicate no default value on struct types, you should now make use of msgspec.NODEFAULT instead (PR #350).

  • Improve struct type annotations now that mypy supports typing.dataclass_transform (PR #352).

  • Support typing.Final annotations for indicating that an object field should be treated as immutable (PR #354).

  • Add a name keyword option to msgspec.field for renaming a single field (PR #356).

  • BREAKING: The rules around class inheritance and a struct’s rename option have changed. See PR #356 for more information.

Version 0.13.1 (2023-02-09)#

  • Fix a memory leak in the JSON decoder introduced in 0.13.0, caused by a reference counting bug when decoding into Struct types (PR #312).

Version 0.13.0 (2023-02-08)#

  • Add to_builtins function for converting messages composed of any supported type to ones composed of only simple builtin types commonly supported by Python serialization libraries (PR #258).

  • Add from_builtins function for converting and validating messages composed of simple builtin types to ones composed of any type msgspec supports (PR #266, PR #302).

  • Add msgspec.yaml module for encoding/decoding YAML (PR #267).

  • Add msgspec.toml module for encoding/decoding TOML (PR #268).

  • Add msgspec.structs.replace function for creating a copy of an existing Struct with some changes applied (PR #262).

  • Add msgspec.structs.asdict and msgspec.structs.astuple functions for converting a struct instance to a dict or tuple respectively (PR #300).

  • Support arbitrarily nested typing.NewType/typing.Annotated types (PR #272).

  • Improve error message for invalid keyword arguments passed to Struct.__init__ (PR #273).

  • Support default_factory configuration for Struct fields (PR #274).

  • BREAKING: With the exception of empty builtin collections ([], {}, set(), bytearray()), mutable default values in Struct types are no longer deepcopied when used. If a different mutable default value is needed, please configure a default_factory instead (PR #274).

  • Improve performance of creating Structs with default parameters (PR #274).

  • Support typing.ClassVar annotations of Struct types (PR #281).

  • Support encoding/decoding decimal.Decimal types (PR #288).

  • Support “abstract” type annotations like collections.abc.MutableMapping/typing.MutableMapping in decoders (PR #290).

  • Support any string-like or int-like type as a dict key when encoding or decoding JSON (PR #292).

  • Improved performance encoding large collections in JSON and MessagePack encoders (PR #294, PR #298).

Version 0.12.0 (2023-01-05)#

  • Support encoding set and frozenset subclasses (PR #249).

  • Support encoding/decoding typing.NewType types (PR #251).

  • Allow creating a msgspec.Raw object from a str (PR #252).

  • Add new experimental msgspec.inspect module for inspecting type annotations. This is intended to be used for building downstream tooling based on msgspec-compatible types. See the docs for more information (PR #253).

  • Add new extra field to msgspec.Meta, for storing arbitrary user-defined metadata (PR #255).

  • Improved performance for JSON encoding strings (PR #256).

Version 0.11.0 (2022-12-19)#

  • Improve performance of constructors for Struct types when using keyword arguments (PR #237).

  • Support Constraints on dict keys for JSON (PR #239).

  • Add support for keyword-only arguments in Struct types, matching the behavior of kw_only for dataclasses (PR #242).

  • BREAKING: Change the parameter ordering rules used by Struct types to match the behavior of dataclasses. For most users this change shouldn’t break anything. However, if your struct definitions have required fields after optional fields, you’ll now get an error on import. This error can be fixed by either:

    • Reordering your fields so all required fields are before all optional fields

    • Using keyword-only parameters (by passing the kw_only=True option).

    See Field Ordering for more information (PR #242).

  • Support encoding/decoding dictionaries with integer keys for JSON (PR #243).

Version 0.10.1 (2022-12-08)#

Version 0.10.0 (2022-12-07)#

Version 0.9.1 (2022-10-27)#

  • Enable Python 3.11 builds (PR #205)

  • Support greater than microsecond resolution when parsing JSON timestamps (PR #201)

  • Work around a limitation in mypy for typed decoders (PR #191)

Version 0.9.0 (2022-09-13)#

  • Support for constraints during validation. For example, this allows ensuring a field is an integer >= 0. (PR #176)

  • New utilities for generating JSON Schemas from type definitions (PR #181)

  • Support for pretty printing using rich (PR #183)

  • Improve integer encoding performance (PR #170)

  • Builtin support for renaming fields using kebab-case (PR #175)

  • Support for passing a mapping when renaming fields (PR #185)

Version 0.8.0 (2022-08-01)#

Version 0.7.1 (2022-06-27)#

  • Further reduce the size of packaged wheels (PR #130).

  • Add weakref support for Struct types through a new weakref configuration option (PR #131).

  • Fix a couple unlikely (but possible) bugs in the deallocation routine for Struct types (PR #131).

Version 0.7.0 (2022-06-20)#

  • Dramatically speedup JSON string decoding, up to 2x speedup in some cases (PR #118).

  • Adds a cache for decoding short (< 32 character) ASCII dict keys. This results in up to a 40% speedup when decoding many dicts with common keys using an untyped decoder. It’s still recommended to define Struct types when your messages have a common structure, but in cases where no type is provided decoding is now much more performant (PR #120, PR #121).

  • Adds order and eq configuration options for Struct types, mirroring the dataclasses options of the same name. Order comparisons for Struct types are very performant, roughly 10x to 70x faster than alternative libraries (PR #122).

  • Speedup Struct decoding for both JSON and MessagePack, on average 20% faster (PR #119).

  • Various additional performance improvements, mostly to the JSON implementation (PR #100, PR #101, PR #102).

  • Add defstruct method for dynamically defining new Struct types at runtime (PR #105).

  • Fix ARM support and publish ARM wheels for Linux and Mac (PR #104).

  • Reduce published wheel sizes by stripping debug symbols (PR #113).

  • Fix a memory leak in Struct.__reduce__ (PR #117).

  • BREAKING: Rename nogc struct option to gc. To disable GC on a Struct instance you now want to specify gc=False instead of nogc=True (PR #124).

Version 0.6.0 (2022-04-06)#

  • Add a new msgspec.Raw type for delayed decoding of message fields / serializing already encoded fields (PR #92).

  • Add omit_defaults option to Struct types (docs). If enabled, fields containing their respective default value will be omitted from serialized message. This improves both encode and decode performance (PR #94).

  • Add rename option to Struct types (docs) for altering the field names used for encoding. A major use of this is supporting camelCase JSON field names, while letting Python code use the more standard snake_case field names (PR #98).

  • Improve performance of nogc=True structs (docs). GC is now avoided in more cases, and nogc=True structs use 16 fewer bytes per instance. Also added a benchmark for how msgspec can interact with application GC usage (PR #93).

  • Cache creation of tagged union lookup tables, reducing memory usage for applications making heavy use of tagged unions (PR #91).

  • Support encoding and decoding frozenset instances (PR #95).

  • A smattering of other performance improvements.

Version 0.5.0 (2022-03-09)#

  • Support tagged unions for encoding/decoding a Union of msgspec.Struct types (PR #83).

  • Further improve encoding performance of enum.Enum instances by 20-30% (PR #84).

  • Reduce overhead of calling msgspec.json.decode/msgspec.msgpack.decode with type=SomeStructType. It’s still faster to create a Decoder once and call decoder.decode multiple times, but for struct types the overhead of calling the top-level function is decreased significantly (PR #77, PR #88).

  • BREAKING: Rename the Struct option asarray to array_like (PR #85).

Version 0.4.2 (2022-02-28)#

  • Support typing.Literal string types as dict keys in JSON (PR #78).

  • Support Python 3.10 style unions (for example, int | float | None) (PR #75).

  • Publish Python 3.10 wheels (PR #80).

Version 0.4.1 (2022-02-23)#

  • Optimize decoding of Enum types, on average ~10x faster (PR #69).

  • Optimize decoding of IntEnum types, on average ~12x faster (PR #68).

  • Support decoding typing.Literal types (PR #71).

  • Add nogc option for Struct types, disabling the cyclic garbage collector for their instances (PR #72).

Version 0.4.0 (2022-02-08)#

  • Moved MessagePack support to the msgspec.msgpack submodule (PR #56).

  • New JSON support available in msgspec.json (PR #56).

  • Improved error message generation to provide full path to the mistyped values (PR #56).

  • Renamed the immutable kwarg in msgspec.Struct to frozen to better match python conventions (PR #60).

  • Renamed EncodingError to EncodeError/DecodingError to DecodeError to better match python conventions (PR #61).

  • Improved pyright support, allowing more errors to be statically caught by their type checker (PR #60).

  • Adds support for Python 3.10 pattern matching on msgspec.Struct types (PR #53).

  • Adds support for decoding into typing.Union types (with a few restrictions) (PR #54).

  • General performance improvements across all encoders/decoders.

Version 0.3.2 (2021-07-23)#

  • Faster float encoding and decoding (PR #47).

  • General micro-optimizations for MessagePack encode/decode. This is most visible for large messages (PR #48, PR #50).

Version 0.3.1 (2021-07-12)#

  • Use a freelist for small structs to improve struct allocation time (PR #44).

  • Small performance improvements for struct serialization (PR #45).

Version 0.3.0 (2021-07-07)#

  • Add Encoder.encode_into api, for encoding into an existing buffer without copying (PR #34).

  • Add support for encoding/decoding MessagePack extensions (PR #31).

  • Add support for encoding/decoding datetime objects (PR #36).

  • Add support for encoding/decoding custom objects without relying on MessagePack extensions (PR #32, PR #33).

  • Add support for marking Struct types as hashable (PR #39).

  • Add support for serializing Struct types as MessagePack array objects rather than map objects (PR #39).

  • Several performance improvements. On average 50% faster encoding and 30% faster decoding.

Version 0.2.0 (2021-02-25)#

  • Add default callback to encode/Encoder (PR #21).

  • Fix bug in Encoder dealloc (PR #21).

Version 0.1.0 (2021-02-23)#

  • Initial Release