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.18.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e986f68cbcba50a2198052692f530113507fb566f282f40cfdaafee7ae6a307 |
|
MD5 | fb46ddbdf870feda353f62ef28b5dadc |
|
BLAKE2b-256 | bd0d324a0384e8b68abc554b4e3cbfd39dae0cbca20590f54ea884e814877cfa |
Hashes for msgspec-0.18.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 722032d40b721bfb0771c8aeba11373bed84c5ed8721cc81360207d67ecfb9ca |
|
MD5 | f4cb53675b3de70cd8981fe2b910ba55 |
|
BLAKE2b-256 | b3a1511d72fc20d86cf37b23ff7ad5815efaf3ff81e7ee6c7dff679a60d3d933 |
Hashes for msgspec-0.18.0-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee81a859b16698d2f43fe6bc56b7141f6dd936a6a80f52ec80da45fafa3d56ea |
|
MD5 | 3c42297af2e729bea16e29de2d2e545a |
|
BLAKE2b-256 | 436e92c89dceba88362fad255fc5a77ae36415bfd76157189f20e393a5f3a677 |
Hashes for msgspec-0.18.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9b59fff158e5a576d68afe3aed040717d25d7edd2c0653c46733dfa0fbfa1c6 |
|
MD5 | 41862c65fe79c3c125dd1c4d4116902c |
|
BLAKE2b-256 | 7c1e145eaf2ba3d4cf1081b3e6f3c14d892d8d59a26f525c2ab39b5f8be43359 |
Hashes for msgspec-0.18.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3db21b8e7c71f011c90ba6ed0514cf4a95076ae48e7e85d5fd912f6c8d609990 |
|
MD5 | ab8ce3f1da713fae354039546abff1e1 |
|
BLAKE2b-256 | c74625067c772645714f7125187d6fb312c254b42ed1cb983c6cf9f5a81cc066 |
Hashes for msgspec-0.18.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33950a523536baceed2f252cda32780eb3646a4656ca08c4bea6497d4988e341 |
|
MD5 | e1903f6f5faf15389c56ddcc8a1e57a3 |
|
BLAKE2b-256 | 70eeca421fce0da8414fc4616f8639b5464621619b13bca56aa4cd658a1f9940 |
Hashes for msgspec-0.18.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08c422741e0e1e13404f7497c2b3419999fd1398c095e841f191d78f569361fd |
|
MD5 | c82780fff137a6b07e0bd83c345b45c3 |
|
BLAKE2b-256 | f907e82ab8c4099e6053454748b94bc769adb1d21b303417627ffa7f4638f438 |
Hashes for msgspec-0.18.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e0d735205bf9abd7755434233b7ff48db66965ca4d50a59a96421c4425b2507 |
|
MD5 | 8730e0e0f4c7a6043d59d905833403b8 |
|
BLAKE2b-256 | 41c4b736fbb2acedec095228806f34de3e84750c55e82098a01e59563545e4aa |
Hashes for msgspec-0.18.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89070b557ae3f057c9357dc7f2f5fe11000808254e3f079663246ae4b43b2b89 |
|
MD5 | e71451db17a9ebd0bc17b982684492d2 |
|
BLAKE2b-256 | 2bf917e6d0b3fe7932ee83a2845405b83a3c7f26e87cde1310a7f05872d645e1 |
Hashes for msgspec-0.18.0-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92c0db3f81bfda2be43ced32b043e68fa95daa5c7403f0ced26e49815efe681e |
|
MD5 | a495a3bd3de0f920756d5904f5e8274f |
|
BLAKE2b-256 | 4b48f1e4e0b3a6b3333f39db2e76756bac398eba4909122dcace4ce7ecf8f78a |
Hashes for msgspec-0.18.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d814fe2b4641085ed4a2fc917b5f407afe550c3d0c00ab190fc1f6fae1c75dd7 |
|
MD5 | b7fae4c3e61dfdb8efc26778b9595acd |
|
BLAKE2b-256 | 9591b850a20730c388ecc60d05dbdceaca2689871e787e01be31c01427a7d9ab |
Hashes for msgspec-0.18.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7bc1386317796508772e95e3747dbea7e4178a24ebba04f33408dd84b6aea44 |
|
MD5 | 28c4bc75d5c91da8f55ef4498e823b41 |
|
BLAKE2b-256 | 24fc7dd63668a178b345655974d10fbd4cc7e970762b9d60caea6881decfa4ba |
Hashes for msgspec-0.18.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d28fcd20d07b565f42289bc7791493cf3b602ad41002db3fe5642802bbf137a |
|
MD5 | 0a95eaa0e4055cf11347fe078090b453 |
|
BLAKE2b-256 | 8bb2d8d875dcbd07bd5550fccfc454eb7458bb81c8fde4812467e9a785f6f2ae |
Hashes for msgspec-0.18.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec4f95f03e9fcaef942f5b76856ad1b6bace5cc4db4555939ff25262faa5ad63 |
|
MD5 | 4b5c127dea731854d541cd95c418bd26 |
|
BLAKE2b-256 | f8be9c859944000f0b1f6d478c1727a463fcfadc2b361f6069f4028d04221a2c |
Hashes for msgspec-0.18.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f907fcc782e5fa6f6bb329004993baa00f068b4e964a971a1421e316b6870012 |
|
MD5 | 31751b600a1539d6f500192af7e04ba0 |
|
BLAKE2b-256 | 8110cd015d4bf6b2d4ef55615b3e121cef2ec1bd2433bb8fe68fcc9ce0be4e87 |
Hashes for msgspec-0.18.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef84977a7f8ced0c369a65ffbcd618c341fe4ba0b30bd1348ce8b6e5dc4096b3 |
|
MD5 | 31dfe9f6d7448a14d05b7d7fe8731589 |
|
BLAKE2b-256 | 38a1f71558be7d9601ccaa520e66e4c5a5973526529e81313b4bf0fb0f45a071 |
Hashes for msgspec-0.18.0-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f78c176e072e5d805be618d62e56cb2d2ca68cb93c0d6bbfeb03418247e529f |
|
MD5 | f2c64b86d1aaf18cff2c10ba0f061517 |
|
BLAKE2b-256 | bbf84b22c04d457214077b2887a00e5557403bf589ad57f6a510eb7d2ccbaff2 |
Hashes for msgspec-0.18.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5f9d154ff486426733726de321d3993f4d8aa7bbea3812a8716dedc6b867592 |
|
MD5 | bf684ebc1896b08a9924a36514f4dd07 |
|
BLAKE2b-256 | 66c540163f1e708ddecd28832dc02c30004cc3a57359eaabbaf2002fec5008ba |
Hashes for msgspec-0.18.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c103a8eb8c01a3594cf3c66fe6d6a4d11e17d52e07bffadff599d87bae4a476 |
|
MD5 | e5522c4fea2f0278d4f61a26b3d05b62 |
|
BLAKE2b-256 | 8da402c8d06835e54fbf257adb89afb50803326b2e040451d3482206cd1408fc |
Hashes for msgspec-0.18.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 005f708354371c2a7c3c598f4a67d23f73315e3789dfefd2a274f4a11097866d |
|
MD5 | 8bec02f8fa04f6595c84ff7d93fdff39 |
|
BLAKE2b-256 | 26bb8e165c6fd8b4a4377295bb58562ce8c67f2c5a2b9a1723e5bd10c4a186ff |
Hashes for msgspec-0.18.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e409af3aa63df802fbe9f99fee1bfdb895f2b243c96e1ef9a40793f73625b549 |
|
MD5 | 8b75d4a26931c7b566b208fbaa2a6cea |
|
BLAKE2b-256 | 8d53baa29e42c7ffb934e0bed141ccd54aec07dc33585582e9a9133ce85ac06a |
Hashes for msgspec-0.18.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbd16fae31bb5d2ce06d317e5f2736d58690cad310147c2104ff0a98fa63895c |
|
MD5 | 7817475d035e34fd0660d01bc618c7a1 |
|
BLAKE2b-256 | b139c22299605e476e9ad9d913c7d167ecd7e80a6b5b497d8b4f9dd46d63fec4 |
Hashes for msgspec-0.18.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 719c8b687a0402d2cd1579753e50d903ab53ef0402bbab91bca96d0e3c2b78d5 |
|
MD5 | b8216954d7dce206b8dc3612c30f4f5f |
|
BLAKE2b-256 | 65291a6c1d8b7aa7e07a5622cf5f9c96f198e61942de46e66d119b6d54736a10 |
Hashes for msgspec-0.18.0-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 047b00a7e148c02e64cbb65c59512f93fb8e96b71fc0358f12062e0359bef878 |
|
MD5 | 79942d4344d6f651bda9ec86a8d1540a |
|
BLAKE2b-256 | d8c5f5c8af859e7abcaf0aef91a44c5d896eb1583720a6e69a21143ce49f98c3 |
Hashes for msgspec-0.18.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf10ad5928aecaaeb6b2be82b8aef78df786734020bfc1f281ee78485daa2af7 |
|
MD5 | 8b94304e9d907c8a5ea2a259dcee3cfe |
|
BLAKE2b-256 | 92751be323ba3de988212363610d1d113ddcb19fa790f695a9c4c48485288627 |
Hashes for msgspec-0.18.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f754b92340188e6e89c51f3fdfab7de0177bcd08919481072c192782ad9ecee5 |
|
MD5 | 03ff1dd7eb622af634d3d5fc6be2476b |
|
BLAKE2b-256 | ae86a56f0f995a6918cd6336b413155fe1227c9dee8b797a9371993202005c2e |
Hashes for msgspec-0.18.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b44ad06f78a4c05860f80bb533893582727777a8cc760573f41e49cfc5cee60c |
|
MD5 | bf330b9bbd5a3632d0caad0efc431f7e |
|
BLAKE2b-256 | 4f1ec61585ede6bdae0295a8cebcf45f09da1d7573782216e48dc49be47fe52e |
Hashes for msgspec-0.18.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c3d6147f1368c8ccf0869313c23ffdf874abb7e0033002689edf5bfc048f75d |
|
MD5 | 5f5b7a91d7ac1a9b6bbf0b04a07f01a6 |
|
BLAKE2b-256 | db4c554ebd68995a3a60a55a3fec2b90778ce07f36516da2ffd90cc2cbd1a2ff |