A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML
BSD-3-CLAUSE License
Bot releases are hidden (Show)
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).Published by jcrist 10 months ago
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).Published by jcrist about 1 year ago
msgspec
on CPython 3.12 (#561)Published by jcrist about 1 year ago
Struct.__rich_repr__
(#557)Published by jcrist about 1 year ago
Enum._missing_
hooks for handling unknown enum values (#532).datetime.datetime
objects with zoneinfo.ZoneInfo
timezone components (#534).attrs
validators (#538).Published by jcrist about 1 year ago
builtin_types
in msgspec.to_builtins
(#517).getattr
before getitem
when converting with from_attributes=True
(#519).Published by jcrist about 1 year ago
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).Published by jcrist over 1 year ago
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).Published by jcrist over 1 year ago
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).Published by jcrist over 1 year ago
datetime
/time
objects in both the msgpack
and json
decoders (#409).Required
/NotRequired
in TypedDict
when __future__.annotations
is enabled (#410).Published by jcrist over 1 year ago
Struct
types (#386, #393).dataclasses
and attrs
types (#396).typing.TypedDict
and typing.NamedTuple
types (#398).datetime
objects from JSON (#391).__qualname__
when auto-generating Struct tags rather than __name__
(#399).typing.Literal
types containing a literal None
(#400).Encoder
/Decoder
methods threadsafe (#402).write_buffer_size
kwarg to Encoder
(#402).Published by jcrist over 1 year ago
__del__
trashcan usage for structs with gc=False
(#369).__setattr__
in Struct types (#376).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 (#381).Published by jcrist over 1 year ago
dict=True
on Python 3.11 #365Published by jcrist over 1 year ago
repr_omit_defaults
configuration option for omitting struct default values in the repr
(#322).__struct_config__
attribute (#328).msgspec.structs.fields
utility function for inspecting the fields configured on a Struct (#330).dict
configuration option for adding a __dict__
attribute to a Struct (#331).lt
and gt
constraints on an integer type (#335).msgspec.field()
with no arguments (#343).msgspec.from_builtins
(#346).int
& bytes
in msgspec.from_builtins
(#346).msgspec.UNSET
and msgspec.UnsetType
for tracking unset fields. See the docs for more information (#350).msgspec.UNSET
singleton to explicitly indicate no default value on struct types, you should now make use of msgspec.NODEFAULT
instead (#350).mypy
supports typing.dataclass_transform
(#352).typing.Final
annotations for indicating that an object field should be treated as immutable (#354).name
keyword option to msgspec.field
for renaming a single field (#356).rename
option have changed. See #356 for more information.Published by jcrist over 1 year ago
Struct
types (#312).Published by jcrist over 1 year ago
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 (#258).from_builtins
function for converting and validating messages composed of simple builtin types to ones composed of any type msgspec supports (#266, #302).msgspec.yaml
module for encoding/decoding YAML (#267).msgspec.toml
module for encoding/decoding TOML (#268).msgspec.structs.replace
function for creating a copy of an existing Struct
with some changes applied (#262).msgspec.structs.asdict
and msgspec.structs.astuple
functions for converting a struct instance to a dict
or tuple
respectively (#300).typing.NewType
/typing.Annotated
types (#272).Struct.__init__
(#273).default_factory
configuration for Struct
fields (#274).[]
, {}
, 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 (#274).typing.ClassVar
annotations of Struct
types (#281).decimal.Decimal
types (#288).collections.abc.MutableMapping
/typing.MutableMapping
in decoders (#290).dict
key when encoding or decoding JSON (#292).Published by jcrist almost 2 years ago
Support encoding set
and frozenset
subclasses (#249).
Support encoding/decoding typing.NewType
types (#251).
Allow creating a msgspec.Raw
object from a str
(#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 (#253).
Add new extra
field to msgspec.Meta
, for storing arbitrary user-defined metadata (#255).
Improved performance for JSON encoding strings (#256).
Published by jcrist almost 2 years ago
Improve performance of constructors for Struct
types when using keyword arguments (#237).
Support constraints on dict keys for JSON (#239).
Add support for keyword-only arguments in Struct
types, matching the behavior of kw_only
for dataclasses
(#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:
kw_only=True
option).See Field Ordering for more information (#242).
Support encoding/decoding dictionaries with integer keys for JSON (#243).
Published by jcrist almost 2 years ago
"_"
) when encoding dataclasses
(#234)Published by jcrist almost 2 years ago
forbid_unknown_fields
configuration option to Struct
types (#210)enum
types by value, rather than name (#211)dataclasses
(#218)datetime.date
objects (#221)uuid.UUID
objects (#222)datetime.datetime
values without timezones by default (#224).tz
constraint to require aware or naive datetime/time objects when decoding (#224).datetime.time
objects (#225)msgspec.json.format
utility for efficiently pretty-printing already encoded JSON documents (#226).