A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML
strict=False
(#619)._
when renaming fields to camel or pascal case (#620).memoryview
(#624).Generic
base class multiple times (#626).order
option to all encoders for enforcing deterministic/sorted ordering when encoding. This can help provide a more consistent or human readable output (#627).Struct
type with gc=False
(#635).Struct
types in msgspec.convert
(#636).Annotated
metadata in msgspec.inspect.type_info
(#566).slots=True, frozen=True
(#569).msgspec.structs.fields
(#571).str
constraints on dict keys when decoding msgpack (#577).UUID
subclasses as inputs to msgspec.convert
(#592).__eq__
from generated __ne__
if user defines manual __eq__
method on a Struct
type (#593).Struct
type in the generated hash (#595).cache_hash
struct option (#596).msgspec.structs.force_setattr
(#600).dict
key constraints in generated JSON schema via the propertyNames
field (#604).schema_hook
for generating JSON schemas for custom types (#605).type
aliases (#606).msgspec
on CPython 3.12 (#561)Struct.__rich_repr__
(#557)Enum._missing_
hooks for handling unknown enum values (#532).datetime.datetime
objects with zoneinfo.ZoneInfo
timezone components (#534).attrs
validators (#538).builtin_types
in msgspec.to_builtins
(#517).getattr
before getitem
when converting with from_attributes=True
(#519).msgspec.json.Decoder.decode_lines
method for decoding newline-delimited JSON into a list of values (#485).edgedb.Object
instances as dataclass-like objects (#501).float
values (#510).float
keys (#510).float
keys (#510).float_hook
to msgspec.json.Decoder
to support changing the default for how JSON floats are decoded (#511).None
may be explicitly passed to defstruct
for module
/namespace
/bases
(#445).datetime.datetime
values from int
/float
values (interpreted as seconds since the Unix epoch) when strict=False
(#452).list
, dict
, ...) as inputs to convert
(#453).str
subclasses as keys in to_builtins
and all protocol encode
methods (#454).decimal.Decimal
values (#455).int
/float
values (#458).str
values (#459).dec_hook
with a ValidationError
(#460).decimal.Decimal
values from numeric values (#463)decimal.Decimal
values as numeric values (#465).decimal.Decimal
values to float
in convert
(#466).int64
/uint64
(#469).__post_init__
method for Struct
types (#470).0
/1
into bool
types when strict=False
(#471).__post_init__
/__attrs_post_init__
in a ValidationError
when decoding (#472).datetime.timedelta
types (#475).msgspec.json.Encoder.encode_lines
method for encoding an iterable of values as newline-delimited JSON (#479).msgspec.from_builtins
in favor of msgspec.convert
. The new convert
function provides a superset of the functionality available in the old from_builtins
function. See the converters docs for more information (#431).from_attributes
argument to msgspec.convert
for allowing conversion between object types with matching attribute names. One use case for this is converting ORM objects to Struct
or dataclasses
types (#419).Mapping
objects as inputs to msgspec.convert
. These may be coerced to dict
/Struct
/dataclasses
/attrs
types (#427).strict
keyword argument to all decode
functions, Decoder
classes, as well as msgspec.convert
. This defaults to True
, setting it to false enables a wider set of coercion rules (e.g. coercing a str
input to an int
). See "Strict" vs "Lax" Mode for more information (#434).msgspec.convert
(#431, #418).typing.Any
type in msgspec.convert
(#435).Decoder
types at runtime (#415).UUID
(#429).datetime
/time
objects in both the msgpack
and json
decoders (#409).Required
/NotRequired
in TypedDict
when __future__.annotations
is enabled (#410).