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 withgc=False
(PR #635).Automatically infer the input field naming convention when converting non-dict mappings or arbitrary objects to
Struct
types inmsgspec.convert
(PR #636).
Version 0.18.5 (2023-12-12)¶
Support unhashable
Annotated
metadata 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
str
constraints on dict keys when decoding msgpack (PR #577).Support
UUID
subclasses as inputs tomsgspec.convert
(PR #592).Call
__eq__
from generated__ne__
if user defines manual__eq__
method on aStruct
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).
Support custom dict key types in JSON encoder and decoder (PR #602).
Include
dict
key constraints in generated JSON schema via thepropertyNames
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)¶
Version 0.18.2 (2023-08-26)¶
Support
Enum._missing_
hooks for handling unknown enum values (PR #532).Fix JSON encoding of
datetime.datetime
objects withzoneinfo.ZoneInfo
timezone components (PR #534).Add support for
attrs
validators (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_types
inmsgspec.to_builtins
(PR #517).Try
getattr
beforegetitem
when 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_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
tomsgspec.json.Decoder
to support changing the default for how JSON floats are decoded (PR #511).
Version 0.17.0 (2023-07-11)¶
Ensure
None
may be explicitly passed todefstruct
formodule
/namespace
/bases
(PR #445).Support decoding
datetime.datetime
values fromint
/float
values (interpreted as seconds since the Unix epoch) whenstrict=False
(PR #452).Support subclasses of collection types (
list
,dict
, …) as inputs toconvert
(PR #453).Support
str
subclasses as keys into_builtins
and all protocolencode
methods (PR #454).Improved performance when JSON encoding
decimal.Decimal
values (PR #455).Improved performance when JSON encoding
int
/float
values (PR #458).Improved performance when JSON encoding
str
values (PR #459).Wrap errors in
dec_hook
with aValidationError
(PR #460).Support decoding
decimal.Decimal
values from numeric values (PR #463)Support encoding
decimal.Decimal
values as numeric values (PR #465).Support converting
decimal.Decimal
values tofloat
inconvert
(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 forStruct
types (PR #470).Support decoding
0
/1
intobool
types whenstrict=False
(PR #471).Wrap errors raised in
__post_init__
/__attrs_post_init__
in aValidationError
when decoding (PR #472).Add native support for encoding/decoding
datetime.timedelta
types (PR #475).Add a new
msgspec.json.Encoder.encode_lines
method for encoding an iterable of values as newline-delimited JSON (PR #479).
Version 0.16.0 (2023-06-12)¶
Deprecate
msgspec.from_builtins
in favor ofmsgspec.convert
. The newconvert
function provides a superset of the functionality available in the oldfrom_builtins
function (PR #431).Add a
from_attributes
argument tomsgspec.convert
for allowing conversion between object types with matching attribute names. One use case for this is converting ORM objects toStruct
ordataclasses
types (PR #419).Support passing generic
Mapping
objects as inputs tomsgspec.convert
. These may be coerced todict
/Struct
/dataclasses
/attrs
types (PR #427).Add a new
strict
keyword argument to alldecode
functions,Decoder
classes, as well asmsgspec.convert
. This defaults toTrue
, setting it to false enables a wider set of coercion rules (e.g. coercing astr
input 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.Any
type inmsgspec.convert
(PR #435).Support parametrizing
Decoder
types 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
/time
objects in both themsgpack
andjson
decoders (PR #409).Work around an upstream bug in CPython to properly support
typing.Required
/typing.NotRequired
intyping.TypedDict
when__future__.annotations
is enabled (PR #410).
Version 0.15.0 (2023-05-10)¶
Add support for Generic
dataclasses
and attrs types (PR #396).Add support for Generic
typing.TypedDict
andtyping.NamedTuple
types (PR #398).BREAKING: No longer normalize timezones to UTC when decoding
datetime
objects 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.Literal
types containing a literalNone
(PR #400).Make all
Encoder
/Decoder
methods threadsafe (PR #402).BREAKING: Drop the
write_buffer_size
kwarg 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_defaults
configuration 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.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
andgt
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
inmsgspec.from_builtins
(PR #346).Add
msgspec.UNSET
andmsgspec.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 ofmsgspec.NODEFAULT
instead (PR #350).Improve struct type annotations now that
mypy
supportstyping.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 tomsgspec.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 existingStruct
with some changes applied (PR #262).Add
msgspec.structs.asdict
andmsgspec.structs.astuple
functions for converting a struct instance to adict
ortuple
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 forStruct
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 adefault_factory
instead (PR #274).Improve performance of creating Structs with default parameters (PR #274).
Support
typing.ClassVar
annotations ofStruct
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
andfrozenset
subclasses (PR #249).Support encoding/decoding
typing.NewType
types (PR #251).Allow creating a
msgspec.Raw
object from astr
(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 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
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 ofkw_only
fordataclasses
(PR #242).BREAKING: Change the parameter ordering rules used by
Struct
types 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=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)¶
Ignore attributes with leading underscores (
"_"
) when encodingdataclasses
(PR #234)
Version 0.10.0 (2022-12-07)¶
Add
forbid_unknown_fields
configuration option toStruct
types (PR #210)BREAKING: Encode all
enum
types 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.date
objects (PR #221)Add support for encoding/decoding
uuid.UUID
objects (PR #222)BREAKING: support encoding/decoding
datetime.datetime
values without timezones by default (PR #224).Add a
tz
constraint to require aware or naive datetime/time objects when decoding (PR #224).Add support for encoding/decoding
datetime.time
objects (PR #225)Add a
msgspec.json.format
utility 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.TypedDict
types (PR #142).Support encoding/decoding
typing.NamedTuple
types (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
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
andeq
configuration options forStruct
types, mirroring thedataclasses
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 newStruct
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 togc
. To disable GC on a Struct instance you now want to specifygc=False
instead 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_defaults
option toStruct
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 toStruct
types (docs) for altering the field names used for encoding. A major use of this is supportingcamelCase
JSON field names, while letting Python code use the more standardsnake_case
field names (PR #98).Improve performance of
nogc=True
structs (docs). GC is now avoided in more cases, andnogc=True
structs use 16 fewer bytes per instance. Also added a benchmark for howmsgspec
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
ofmsgspec.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
withtype=SomeStructType
. It’s still faster to create aDecoder
once and calldecoder.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
toarray_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.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 inmsgspec.Struct
tofrozen
to better match python conventions (PR #60).Renamed
EncodingError
toEncodeError
/DecodingError
toDecodeError
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)¶
Version 0.3.1 (2021-07-12)¶
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 MessagePackarray
objects rather thanmap
objects (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