A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML.
Project description
msgspec
is a fast serialization and validation library, with builtin
support for JSON, MessagePack,
YAML, and TOML. It features:
-
🚀 High performance encoders/decoders for common protocols. The JSON and MessagePack implementations regularly benchmark as the fastest options for Python.
-
🎉 Support for a wide variety of Python types. Additional types may be supported through extensions.
-
🔍 Zero-cost schema validation using familiar Python type annotations. In benchmarks
msgspec
decodes and validates JSON ~2x faster than orjson can decode it alone. -
✨ A speedy Struct type for representing structured data. If you already use dataclasses or attrs, structs should feel familiar. However, they're 10-100x faster for common operations.
All of this is included in a lightweight library with no required dependencies.
msgspec
may be used for serialization alone, as a faster JSON or
MessagePack library. For the greatest benefit though, we recommend using
msgspec
to handle the full serialization & validation workflow:
Define your message schemas using standard Python type annotations.
>>> import msgspec
>>> class User(msgspec.Struct):
... """A new type describing a User"""
... name: str
... groups: set[str] = set()
... email: str | None = None
Encode messages as JSON, or one of the many other supported protocols.
>>> alice = User("alice", groups={"admin", "engineering"})
>>> alice
User(name='alice', groups={"admin", "engineering"}, email=None)
>>> msg = msgspec.json.encode(alice)
>>> msg
b'{"name":"alice","groups":["admin","engineering"],"email":null}'
Decode messages back into Python objects, with optional schema validation.
>>> msgspec.json.decode(msg, type=User)
User(name='alice', groups={"admin", "engineering"}, email=None)
>>> msgspec.json.decode(b'{"name":"bob","groups":[123]}', type=User)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
msgspec.ValidationError: Expected `str`, got `int` - at `$.groups[0]`
msgspec
is designed to be as performant as possible, while retaining some of
the nicities of validation libraries like
pydantic. For supported types,
encoding/decoding a message with msgspec
can be
~10-80x faster than alternative libraries.
See the documentation for more information.
LICENSE
New BSD. See the License File.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for msgspec-0.16.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccd842d25593fbff6505e77e0a3701c89bf3a1c260247e4e541e4e58dc81a6cc |
|
MD5 | 6f44bcf11312be5755052e8a0372d980 |
|
BLAKE2b-256 | 92a4e45ce360313624826aeea7da764330760ff262bfc876ead24e877c5a2d0f |
Hashes for msgspec-0.16.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1a6708408cd5a44e39aa268086fe0992001e5881282c178a158af86727ddfa3 |
|
MD5 | 5c19c028fbaa8dc5307caddf800a17ed |
|
BLAKE2b-256 | 80f530f381ad8363558b7f98a38ffcff03ad4ddc33dadc92a90fa7c8b18eb50f |
Hashes for msgspec-0.16.0-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b6412c20bd687df6fb7c72a8a1bbc1a5da1be948bc01ce3d21e645263cddb6c |
|
MD5 | 023b4ed632af83cb4293312b30a2ab75 |
|
BLAKE2b-256 | ad501732733c6b725bb3eed633e57357f9ced2ce24d804a06538ddb958e9e6b0 |
Hashes for msgspec-0.16.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71f710d8b1992cf0690c9feeebd741d69c3627bace3f16e09e8556d65eb012fe |
|
MD5 | 0987525eba8e65d748c1c2557e1971c5 |
|
BLAKE2b-256 | 599f0208124aab3c77492c683d02f0e0dc74ec502293e3c513794193b24d58ba |
Hashes for msgspec-0.16.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9075d40d7739228b6158969239ad7708f483bbd4e8eb09c92c95c6062b470617 |
|
MD5 | eff31138836ea3d4f6d68bb2ae1874f9 |
|
BLAKE2b-256 | a1aa46c9ed3811f0d924ad6bcffe42e097875d7ecd03c277c2828bd68668f396 |
Hashes for msgspec-0.16.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a4f641e10d4ef70a77184c002ec1512c0b83ddbb6c21314c85f9507c029b997 |
|
MD5 | b855234a782379b78e502bbd1a142c4f |
|
BLAKE2b-256 | 59ad19fa77e13065d44522a0c2acd01ce31247c07fd0d56567930b47330b2f49 |
Hashes for msgspec-0.16.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cdfad50f388d1c1a933d9239913cb3bd993d4b631011df34d893fb3011971e0 |
|
MD5 | d887a8ade58b9e1f9a8ab74e1eb532fe |
|
BLAKE2b-256 | ca59c5c4a6928af631933d831e0a1594c7d5859cea0c0b447be9660d8db92165 |
Hashes for msgspec-0.16.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbd657cc2e2840f86a75c1fee265854835e2196d12502a64ce1390239cca58a9 |
|
MD5 | 19003ce706ad173eb796461317dd9330 |
|
BLAKE2b-256 | 1447a456bcfa5c79db2900b482c5fd72016e38a0a34f76a5f1c3afa6ce2c56f1 |
Hashes for msgspec-0.16.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce21b56ecb462abb5291863c2e29dc58177da3c8f43f3d0edf69009daca05b66 |
|
MD5 | ba25fd5808c3bdc31cf5c6f8032d460b |
|
BLAKE2b-256 | 9242a7db9a0efb1b0651b7c1f9ded5279ce618fff27365fa3c2cb5b96825e101 |
Hashes for msgspec-0.16.0-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0458cf8a44f630d372348d95b3b536a52412d4e61a53a3f3f31f070c95eb461 |
|
MD5 | 90c299b5b37a02a2ced9413d3d2aa087 |
|
BLAKE2b-256 | ca943ee60df70d2cc9722613288d1da86e277c9702d1558ca9bc84d42e59986c |
Hashes for msgspec-0.16.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddebe801459cd6f67e4279b3c679dc731729fabf64f42d7a4bd567ca3eb56377 |
|
MD5 | 6f02531c61787c4d21d8da6a7599eeb0 |
|
BLAKE2b-256 | 3e6dc5883a17b889e6aabd254e30aefc72b2df31775beef2669e176e5f90bc12 |
Hashes for msgspec-0.16.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0cda74ffda2b2757eadf2259f8a68a5321f4fb8423bff26fa9e28eaaf8720d6 |
|
MD5 | e1c68ce1f3f483103dc7ffd6683f924e |
|
BLAKE2b-256 | 47f7325b1208e86f46b49ca0b5951b114a75f7853884b39be5f2a523c41f0422 |
Hashes for msgspec-0.16.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77b19814d7206542927c46e0c7807955739c181fef71f973e96c4e47a14c5893 |
|
MD5 | d08ce8bfa59ff3f1feee58fc426f3cd8 |
|
BLAKE2b-256 | 9b0b7c037ca1c3184f29b3ed89ab59791248d5397f9066a894e5017c390d55b1 |
Hashes for msgspec-0.16.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f06692e976bbb89d1c1eb95109679195a4ec172fbec73dee5027af1450f46b59 |
|
MD5 | c3e02adb380be005ef57a20431f8f896 |
|
BLAKE2b-256 | 093155b0ff9457b6ed5f632eb8eed93a1026864a04fbdf1b50a5400386da8952 |
Hashes for msgspec-0.16.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21095c687ae624a812a13a7e5d4ea6f3039c8768052ac0fb2818b8744779872a |
|
MD5 | 98543b72718740aeff27124bb87c7334 |
|
BLAKE2b-256 | 99fdde0cb93852a44a0c43e1a22ba4e8bc2de27108b0b4d030dfd6c94b1dfe91 |
Hashes for msgspec-0.16.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d80d2c1a8e3ee2b991d7fcf8d8b0904cb4fa68fe4d5abf8739453cffdde418c4 |
|
MD5 | 1783db744b97f82a30fead9695cd9fc1 |
|
BLAKE2b-256 | e4dfc36d1b86b6988e864e812c9f359efadf6fd6656848303ed937e18f79f3be |
Hashes for msgspec-0.16.0-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fea1bc172bd07a427ee538169b6447433dee018624f1e43ab7d046ccfbffb66f |
|
MD5 | 7e3bdb75376c09efde31a58704ae97f8 |
|
BLAKE2b-256 | e51b595b7d04134ab5a695c10cf6f0a9b2a6ecad8787dcbcc5b046a7bcb4f407 |
Hashes for msgspec-0.16.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4830b073860e05d2cf1ef56d610035402f83b129a2742032ef2492d093385ef |
|
MD5 | 33c7ec393a1bf15d1a4779e5863e0d42 |
|
BLAKE2b-256 | 85f95efe408f23a2f6b37a8ac133133feeb06a59c6f16be9d377dbd473862470 |
Hashes for msgspec-0.16.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78f3a914a356daf334f9dc7e72fb55025b39c65b6fcec507b18cdca7e65b97f6 |
|
MD5 | 0b505223e3a2e281b9ed1da5b2589ce1 |
|
BLAKE2b-256 | b5d2e14ed608369cf5b3505054a0694a29eb4a68b6b305526bf2170c3714abd1 |
Hashes for msgspec-0.16.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f14e3b1df80967aef772c9ac083df56ecf067f7cad7d291180f2733449e83a5 |
|
MD5 | 9ad49dad857fd4902f675de7525f56b5 |
|
BLAKE2b-256 | 2fde34adbebf6740d312e7da4e677798e812fd9a13da302627127eb9ee384237 |
Hashes for msgspec-0.16.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24809b66ef632f1ae91af7d281dd78eec2f516ad9963b3e9e61cb7b34495875d |
|
MD5 | e56193e66625c909db134a363b0ca368 |
|
BLAKE2b-256 | d386173a34c6cdff2728f063fefff837cdcbdd8b3710661d57017959fd1437d5 |
Hashes for msgspec-0.16.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4111ab4373c185df543248d86eeb885c623319f82f4256164617beb8fbfa5071 |
|
MD5 | 7ce1dce69bb050a8e417d18210392e17 |
|
BLAKE2b-256 | da472cfd3c4f55a83f62a45e3cfede26b4740991bbc22bd96db6ab60056aa27d |
Hashes for msgspec-0.16.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15c64bbefd34a5beb0da9eb22bff3ba0aab296f9828084998cd7716b5c1e2964 |
|
MD5 | 6fa50265d3c4acf8e6a105a9f22ab40f |
|
BLAKE2b-256 | 5b79fbaf344f58c9f5bcdfecd35087b655d147d41e700cb278956de51ab287db |
Hashes for msgspec-0.16.0-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa4bb83597ad8fce23b53ff16acd7931a55bf4ee2197c0282f077e5caacd5ee2 |
|
MD5 | d72c65318bc07f2b9cab2e1a645f3ab7 |
|
BLAKE2b-256 | 69e37fef6609ca913fd766f019fce7c1f4fc0d50f379919056731cd0eb939686 |
Hashes for msgspec-0.16.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86db3b2e32be73d155525e0886764963379eef8d6f7a16da6cd023516aed01ee |
|
MD5 | cdbddecfed86d843fd28e02d3058aec1 |
|
BLAKE2b-256 | 3e911b70776f31b214b1995bdd6b1df66bcafbbf738a6b9b60211165fa6156bd |
Hashes for msgspec-0.16.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36e177b0f05f05321e415d42a30f854df47452c973e18957899410163da5c88c |
|
MD5 | 3408fbe238a80a32b5ff2ede892011c8 |
|
BLAKE2b-256 | b66bc9eab9931ea35481d77d290d49beee339a2152cfa9e2a4a263a99705bea7 |
Hashes for msgspec-0.16.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 611c90eff0e2dd19b53e93bf8040450404f262aa05eee27089c8d29e92031db6 |
|
MD5 | 6a3675b06d640187bc8d1113e5667f9e |
|
BLAKE2b-256 | d11df883a9e61b1c6a21437cda853225a9543d3730b887cdbc39179c216a5607 |
Hashes for msgspec-0.16.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbc137f037c2cb4ee731ef5066d3cb85a639b5d805df7f4c96aaefd914c7c5af |
|
MD5 | b4598cd66de78441e46fd882399aa8ce |
|
BLAKE2b-256 | 852df4e0512b6b316b5309e9f573a7b56c9463495eaa447e0a13db468baeebff |