Changelog¶
Version 0.19.0 (2024-12-27)¶
Improve JSON encoding performance by up to 40% (PR #647).
Ensure
tupleandfrozensetdefault values are treated identically whether specified by value ordefault_factory(PR #653).Fix memory leak of
match_argsinStructConfigobject (PR #684).Fix memory leak in
Raw.copy()(PR #709).Update
decodesignatures for PEP 688 (PR #740).Generate
__replace__method onStructtypes, for use withcopy.replace(PR #747).Fix incorrect decoding of certain > 64 bit integers (PR #751).
Call
__post_init__when converting from an object to a Struct (PR #752).BREAKING: Expand buffer when
encode_intois passed a buffer smaller thanoffset(PR #753).Error nicely when a dataclass type (instead of an instance) is passed to
encode(PR #755).Add support for Python 3.13 (PR #711).
Remove deprecated
from_builtins(PR #761).Support encoding any
Enumtype whose.valueis a supported type (PR #757).Don’t fail eagerly when processing generic types with unsupported
__parameters__(PR #772).Use
eval_type_backportto backport type annotations to Python 3.9 (PR #773).
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
Genericbase class multiple times (PR #626).Add an
orderoption 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
Structtype withgc=False(PR #635).Automatically infer the input field naming convention when converting non-dict mappings or arbitrary objects to
Structtypes inmsgspec.convert(PR #636).
Version 0.18.5 (2023-12-12)¶
Support unhashable
Annotatedmetadata inmsgspec.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
strconstraints on dict keys when decoding msgpack (PR #577).Support
UUIDsubclasses as inputs tomsgspec.convert(PR #592).Call
__eq__from generated__ne__if user defines manual__eq__method on aStructtype (PR #593).Include the
Structtype in the generated hash (PR #595).Add a
cache_hashstruct option (PR #596).Fix a bug around caching of dataclass type info when dealing with subclasses of dataclasses (PR #599).
Support custom dict key types in JSON encoder and decoder (PR #602).
Include
dictkey constraints in generated JSON schema via thepropertyNamesfield (PR #604).Add a
schema_hookfor generating JSON schemas for custom types (PR #605).Add support for Python 3.12’s
typealiases (PR #606).
Version 0.18.4 (2023-10-04)¶
Resolve an issue leading to periodic segfaults when importing
msgspecon CPython 3.12 (PR #561)
Version 0.18.3 (2023-10-03)¶
Version 0.18.2 (2023-08-26)¶
Support
Enum._missing_hooks for handling unknown enum values (PR #532).Fix JSON encoding of
datetime.datetimeobjects withzoneinfo.ZoneInfotimezone components (PR #534).Add support for
attrsvalidators (PR #538).Relax datetime/time parsing format to allow some RFC3339 extensions from ISO8601 (PR #539).
Version 0.18.1 (2023-08-16)¶
Support custom
builtin_typesinmsgspec.to_builtins(PR #517).Try
getattrbeforegetitemwhen converting withfrom_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_linesmethod 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.Objectinstances as dataclass-like objects (PR #501).Improve performance when json decoding
floatvalues (PR #510).Support for JSON encoding dicts with
floatkeys (PR #510).Support for JSON decoding dicts with
floatkeys (PR #510).Add
float_hooktomsgspec.json.Decoderto support changing the default for how JSON floats are decoded (PR #511).
Version 0.17.0 (2023-07-11)¶
Ensure
Nonemay be explicitly passed todefstructformodule/namespace/bases(PR #445).Support decoding
datetime.datetimevalues fromint/floatvalues (interpreted as seconds since the Unix epoch) whenstrict=False(PR #452).Support subclasses of collection types (
list,dict, …) as inputs toconvert(PR #453).Support
strsubclasses as keys into_builtinsand all protocolencodemethods (PR #454).Improved performance when JSON encoding
decimal.Decimalvalues (PR #455).Improved performance when JSON encoding
int/floatvalues (PR #458).Improved performance when JSON encoding
strvalues (PR #459).Wrap errors in
dec_hookwith aValidationError(PR #460).Support decoding
decimal.Decimalvalues from numeric values (PR #463)Support encoding
decimal.Decimalvalues as numeric values (PR #465).Support converting
decimal.Decimalvalues tofloatinconvert(PR #466).Preliminary support for CPython 3.12 beta releases (PR #467).
Support decoding integers that don’t fit into an
int64/uint64(PR #469).Add a new optional
__post_init__method forStructtypes (PR #470).Support decoding
0/1intobooltypes whenstrict=False(PR #471).Wrap errors raised in
__post_init__/__attrs_post_init__in aValidationErrorwhen decoding (PR #472).Add native support for encoding/decoding
datetime.timedeltatypes (PR #475).Add a new
msgspec.json.Encoder.encode_linesmethod for encoding an iterable of values as newline-delimited JSON (PR #479).
Version 0.16.0 (2023-06-12)¶
Deprecate
msgspec.from_builtinsin favor ofmsgspec.convert. The newconvertfunction provides a superset of the functionality available in the oldfrom_builtinsfunction (PR #431).Add a
from_attributesargument tomsgspec.convertfor allowing conversion between object types with matching attribute names. One use case for this is converting ORM objects toStructordataclassestypes (PR #419).Support passing generic
Mappingobjects as inputs tomsgspec.convert. These may be coerced todict/Struct/dataclasses/attrstypes (PR #427).Add a new
strictkeyword argument to alldecodefunctions,Decoderclasses, as well asmsgspec.convert. This defaults toTrue, setting it to false enables a wider set of coercion rules (e.g. coercing astrinput to anint). See “Strict” vs “Lax” Mode for more information (PR #434).Support all Supported Types as inputs to
msgspec.convert(PR #431, PR #418).Passthrough input unchanged when coercing to
typing.Anytype inmsgspec.convert(PR #435).Support parametrizing
Decodertypes at runtime (PR #415).Support encoding subclasses of
UUID(PR #429).
Version 0.15.1 (2023-05-19)¶
Fix a reference counting bug introduced in 0.15.0 when decoding naive (no timezone)
datetime/timeobjects in both themsgpackandjsondecoders (PR #409).Work around an upstream bug in CPython to properly support
typing.Required/typing.NotRequiredintyping.TypedDictwhen__future__.annotationsis enabled (PR #410).
Version 0.15.0 (2023-05-10)¶
Add support for Generic
dataclassesand attrs types (PR #396).Add support for Generic
typing.TypedDictandtyping.NamedTupletypes (PR #398).BREAKING: No longer normalize timezones to UTC when decoding
datetimeobjects from JSON (PR #391).Support decoding unhyphenated UUIDs (PR #392).
Dedent docstrings for descriptions when generating JSON schemas (PR #397).
Use a variant of
__qualname__when auto-generating Struct tags rather than__name__(PR #399).Fix bug when handling
typing.Literaltypes containing a literalNone(PR #400).Make all
Encoder/Decodermethods threadsafe (PR #402).BREAKING: Drop the
write_buffer_sizekwarg toEncoder(PR #402).
Version 0.14.2 (2023-04-19)¶
Remove
__del__trashcan usage for structs withgc=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)¶
Version 0.14.0 (2023-04-02)¶
Add
repr_omit_defaultsconfiguration option for omitting struct default values in therepr(PR #322).Expose a struct’s configuration through a
__struct_config__attribute (PR #328).Add
msgspec.structs.fieldsutility function for inspecting the fields configured on a Struct (PR #330).Add a
dictconfiguration 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
ltandgtconstraints 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&bytesinmsgspec.from_builtins(PR #346).Add
msgspec.UNSETandmsgspec.UnsetTypefor tracking unset fields. See the docs for more information (PR #350).BREAKING: In the unlikely event you were using the previous
msgspec.UNSETsingleton to explicitly indicate no default value on struct types, you should now make use ofmsgspec.NODEFAULTinstead (PR #350).Improve struct type annotations now that
mypysupportstyping.dataclass_transform(PR #352).Support
typing.Finalannotations for indicating that an object field should be treated as immutable (PR #354).Add a
namekeyword option tomsgspec.fieldfor renaming a single field (PR #356).BREAKING: The rules around class inheritance and a struct’s
renameoption 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
Structtypes (PR #312).
Version 0.13.0 (2023-02-08)¶
Add
to_builtinsfunction 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_builtinsfunction for converting and validating messages composed of simple builtin types to ones composed of any type msgspec supports (PR #266, PR #302).Add
msgspec.yamlmodule for encoding/decoding YAML (PR #267).Add
msgspec.tomlmodule for encoding/decoding TOML (PR #268).Add
msgspec.structs.replacefunction for creating a copy of an existingStructwith some changes applied (PR #262).Add
msgspec.structs.asdictandmsgspec.structs.astuplefunctions for converting a struct instance to adictortuplerespectively (PR #300).Support arbitrarily nested
typing.NewType/typing.Annotatedtypes (PR #272).Improve error message for invalid keyword arguments passed to
Struct.__init__(PR #273).Support
default_factoryconfiguration forStructfields (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 adefault_factoryinstead (PR #274).Improve performance of creating Structs with default parameters (PR #274).
Support
typing.ClassVarannotations ofStructtypes (PR #281).Support encoding/decoding
decimal.Decimaltypes (PR #288).Support “abstract” type annotations like
collections.abc.MutableMapping/typing.MutableMappingin decoders (PR #290).Support any string-like or int-like type as a
dictkey 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
setandfrozensetsubclasses (PR #249).Support encoding/decoding
typing.NewTypetypes (PR #251).Allow creating a
msgspec.Rawobject from astr(PR #252).Add new experimental
msgspec.inspectmodule 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
extrafield tomsgspec.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
Structtypes when using keyword arguments (PR #237).Support Constraints on dict keys for JSON (PR #239).
Add support for keyword-only arguments in
Structtypes, matching the behavior ofkw_onlyfordataclasses(PR #242).BREAKING: Change the parameter ordering rules used by
Structtypes to match the behavior ofdataclasses. 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=Trueoption).
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)¶
Ignore attributes with leading underscores (
"_") when encodingdataclasses(PR #234)
Version 0.10.0 (2022-12-07)¶
Add
forbid_unknown_fieldsconfiguration option toStructtypes (PR #210)BREAKING: Encode all
enumtypes by value, rather than name (PR #211)Fix a bug in the JSON encoder when base64 encoding binary objects (PR #217)
Add support for encoding/decoding
dataclasses(PR #218)Add support for encoding/decoding
datetime.dateobjects (PR #221)Add support for encoding/decoding
uuid.UUIDobjects (PR #222)BREAKING: support encoding/decoding
datetime.datetimevalues without timezones by default (PR #224).Add a
tzconstraint to require aware or naive datetime/time objects when decoding (PR #224).Add support for encoding/decoding
datetime.timeobjects (PR #225)Add a
msgspec.json.formatutility for efficiently pretty-printing already encoded JSON documents (PR #226).Support decoding JSON from strings instead of just bytes-like objects (PR #229)
Version 0.9.1 (2022-10-27)¶
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)
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)¶
Support integer tag values when using tagged unions (PR #135).
Support decoding into
typing.TypedDicttypes (PR #142).Support encoding/decoding
typing.NamedTupletypes (PR #161).Test against CPython 3.11 prelease builds (PR #146).
Add
ValidationError(a subclass ofDecodeError) to allow differentiating between errors due to a message not matching the schema from those due to the message being invalid JSON (PR #155).Fix a bug preventing decoding custom types wrapped in a
typing.Optional(PR #162).
Version 0.7.1 (2022-06-27)¶
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
Structtypes 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
orderandeqconfiguration options forStructtypes, mirroring thedataclassesoptions of the same name. Order comparisons for Struct types are very performant, roughly 10x to 70x faster than alternative libraries (PR #122).Speedup
Structdecoding 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
defstructmethod for dynamically defining newStructtypes 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
nogcstruct option togc. To disable GC on a Struct instance you now want to specifygc=Falseinstead ofnogc=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_defaultsoption toStructtypes (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
renameoption toStructtypes (docs) for altering the field names used for encoding. A major use of this is supportingcamelCaseJSON field names, while letting Python code use the more standardsnake_casefield names (PR #98).Improve performance of
nogc=Truestructs (docs). GC is now avoided in more cases, andnogc=Truestructs use 16 fewer bytes per instance. Also added a benchmark for howmsgspeccan 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
frozensetinstances (PR #95).A smattering of other performance improvements.
Version 0.5.0 (2022-03-09)¶
Support tagged unions for encoding/decoding a
Unionofmsgspec.Structtypes (PR #83).Further improve encoding performance of
enum.Enuminstances by 20-30% (PR #84).Reduce overhead of calling
msgspec.json.decode/msgspec.msgpack.decodewithtype=SomeStructType. It’s still faster to create aDecoderonce and calldecoder.decodemultiple 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
asarraytoarray_like(PR #85).
Version 0.4.2 (2022-02-28)¶
Version 0.4.1 (2022-02-23)¶
Version 0.4.0 (2022-02-08)¶
Moved MessagePack support to the
msgspec.msgpacksubmodule (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
immutablekwarg inmsgspec.Structtofrozento better match python conventions (PR #60).Renamed
EncodingErrortoEncodeError/DecodingErrortoDecodeErrorto better match python conventions (PR #61).Improved
pyrightsupport, allowing more errors to be statically caught by their type checker (PR #60).Adds support for Python 3.10 pattern matching on
msgspec.Structtypes (PR #53).Adds support for decoding into
typing.Uniontypes (with a few restrictions) (PR #54).General performance improvements across all encoders/decoders.
Version 0.3.2 (2021-07-23)¶
Version 0.3.1 (2021-07-12)¶
Version 0.3.0 (2021-07-07)¶
Add
Encoder.encode_intoapi, for encoding into an existing buffer without copying (PR #34).Add support for encoding/decoding MessagePack extensions (PR #31).
Add support for encoding/decoding
datetimeobjects (PR #36).Add support for encoding/decoding custom objects without relying on MessagePack extensions (PR #32, PR #33).
Add support for marking
Structtypes as hashable (PR #39).Add support for serializing
Structtypes as MessagePackarrayobjects rather thanmapobjects (PR #39).Several performance improvements. On average 50% faster encoding and 30% faster decoding.
Version 0.2.0 (2021-02-25)¶
Version 0.1.0 (2021-02-23)¶
Initial Release