msgspec
msgspec copied to clipboard
A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML
### Question I tried to make serializable exceptions using: ``` import msgspec class TaggedException(msgspec.Struct, Exception, tag=True): pass ``` However, this reliably segfaults Python (CPython 3.12.5, msgspec 0.18.6). I presume there...
### Question I've reviewed other issues related to tagged unions. But I just wanted to see if there is some magic I can use. In using tagged unions, I kinda...
### Question Hi. How can I create a class that is a msgspec.struct class, but it is not intended to be instantiated directly? Example: ``` class Entity(msgspec.Struct, ABC): ``` ```...
### Description Per the [documentation of UNSET](https://jcristharif.com/msgspec/supported-types.html#unset): > During encoding, any field containing UNSET is omitted from the message. Unfortunately, this fails for Structs with `array_like=True`, resulting in the following...
Fixes #723
### Description When setting both `omit_defaults` and `array_like` to `True`, defaults are _not_ omitted. For example, _without_ `array_like=True`: ```python class Position( msgspec.Struct, frozen=True, forbid_unknown_fields=True, omit_defaults=True, ): longitude: float latitude: float...
### Description I'm trying to use msgspec in a (historically pydantic-based) codebase that uses a self-referencing type declaration to describe contents that can be successfully serialized as JSON. Unfortunately, msgspec...
I can close this if https://github.com/jcrist/msgspec/pull/703 gets more attention, but I've confirmed changes here allow the wheels to be built in 3.8-3.13, and all tests are passing. This warning is...
### Description I have a struct field that is a collection of str (e.g., `Sequence[str]`) and I want to restrict each element of the collection to a `pattern`, but `pattern`...
### Question I made a comment on a closed issue (https://github.com/jcrist/msgspec/issues/568) and I'm not sure it got any visibility so I'm creating a new one instead. Here's a copy-pasta of...