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
~2-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.13.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36b919dad8cbf98d1e2b3d829bf26fbe64205a08ee1caa6988581e5850bcb6b1 |
|
MD5 | d1efae18cfc7a3e0fe3b76ce1547d14f |
|
BLAKE2b-256 | 3987a177d891844dbc5fc86f86c6c294e51221e17c7f869f4afb616401c1a53c |
Hashes for msgspec-0.13.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de920ff863aceef8304a1c5c3855f089782429f6fdbfea1321061f37e4ba418a |
|
MD5 | 76cdc43bb4389913983199870fb37560 |
|
BLAKE2b-256 | 1ff7cf76b8e0e7a911624d088ac4c4a14a7fd8c3dd8275cae8f138977017f59d |
Hashes for msgspec-0.13.1-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d32dedfeb5646ac339eb4602886861756f050c6307e2177b7c68f5084519069 |
|
MD5 | eb3be9162562de7bb4b9f610d84b2bf3 |
|
BLAKE2b-256 | 83ce594b8632230fc923d84af912055f91f7627e56fe4050cc949085ffe9a0d0 |
Hashes for msgspec-0.13.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b0e594996a042fb6dcd9839094b6ef8768e7707bf1567e4d61cbf07c1d12f24 |
|
MD5 | fae7fe8635c677a0648f7eb45ae04b42 |
|
BLAKE2b-256 | ac54dd0e34241074a72cf11bd9ccd2d368fbd53c5b243e1761ab60281afadaa9 |
Hashes for msgspec-0.13.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac902ccdfa4574498342d06f4c49bfa60317724737985b2fc954e8c8eb009910 |
|
MD5 | 8925e7e312289140636682b10d35911c |
|
BLAKE2b-256 | 5712ea8b9d424c6beb6371fc84543b65e34de08f16d6fe481076675875a54f69 |
Hashes for msgspec-0.13.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8853fdf1c44cb874c786133ce1062b6d9a484e0fa48f7174035eb506f462042 |
|
MD5 | 75051dd21a7c4741b5abcc6d53f9d701 |
|
BLAKE2b-256 | a32006458192e69c7413cb74a46ef63532d4de289e321394afc88ce460f7c143 |
Hashes for msgspec-0.13.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 494de96dc6ad90c2f3ba96130591ade518dfd019be767e6030c73ea3e9eb6df9 |
|
MD5 | a28142ea6a7521626cb37f3d935ee532 |
|
BLAKE2b-256 | fb6c8852f811b9814fac0ed8c4c87413ee4c1f75f54bc1cc013f8aea22a37ded |
Hashes for msgspec-0.13.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88466f804b817151cbff9e53d698f86a9280b0d00896302abb528be01c46701a |
|
MD5 | 59691c06ed31480d33efcf8e11928594 |
|
BLAKE2b-256 | db9fb8b56d4969f611e17ee1d751e510d7697a7204c02f8c281c504444af4709 |
Hashes for msgspec-0.13.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99d239343d2b78ad139277067e727ad573445eec6b7ba113e4b987e15728d9d4 |
|
MD5 | 8ff295cac68d67c5e6cca996821eb476 |
|
BLAKE2b-256 | ce2858a4b126f7f08247283f9b3faf1182a1c898892132c9f4abacc33e57d029 |
Hashes for msgspec-0.13.1-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f0679fbafb889e4165bf49c2afd342716dcee2fe13de3777f1613c09740f304 |
|
MD5 | c58ca01ec9ce00779ddd3aedead0f7df |
|
BLAKE2b-256 | c9ecf7d7f74182bd7cec6615d1418a47df5c792d3cf0516d244b3fa5cd5d9932 |
Hashes for msgspec-0.13.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 037ff80d956bb13fc8c221a386f7ba97f6e55d0dc84f4bfe92226df570140802 |
|
MD5 | 2192b06ae777fcbccd54e4adb375775f |
|
BLAKE2b-256 | 40fa39fa76e32922804d2d181ca8f6c0d8a12f5682b007f10f1330e18140043e |
Hashes for msgspec-0.13.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea1d6de944dd2d369186ce9f3d98119980427fd8fba0788d819d775fe0440442 |
|
MD5 | 7af2ddb140adf51075253ff78a6ed2a8 |
|
BLAKE2b-256 | 1ea1ad19de40b63eaef8b521af2e5144875a7054387cb6fb32383b6c89a55a15 |
Hashes for msgspec-0.13.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 014e6e0b01946528f609102c5624749501f63ebdeba386855948185288bc299d |
|
MD5 | 2ac785981ad90703cb9cd5e19a90f43d |
|
BLAKE2b-256 | dec75841566196ec0967c2eff6990ea0cc1a6440efc570525f1950a521c915b0 |
Hashes for msgspec-0.13.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a07a50afb119728e4969ab58602985549b8b9af6cf565873fad28365eb7dbf7b |
|
MD5 | d1e7b62db25f44480dcdfae117e7658d |
|
BLAKE2b-256 | d6983371ebbc14ea21881e8f1e70edc5deda96d718529cea3ba870cbdb1fb39d |
Hashes for msgspec-0.13.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 358da53e870d8bdb890b27c2cd9a670bc17c1d4330908d3fb6e00dcdc8d9c54c |
|
MD5 | 44e9410512868bf0b0a32e00aed2256f |
|
BLAKE2b-256 | 9231b592ee65ee73c85ec999c7452587c6c7a9aec6a9ef22a85e416074168ef5 |
Hashes for msgspec-0.13.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf92cbef573127966cccce71eb9368a6ce36c847ee128e048c7c04724daae855 |
|
MD5 | c3328a08834167ad0db01d6fbe3d82bb |
|
BLAKE2b-256 | de574d6ed10394136f725c24f225ad24a4af15316ba880d245b323e74cf95d78 |
Hashes for msgspec-0.13.1-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59e572b78da8264b2ce3dbb65bec6a4a65cb355046b0d5fc16df24626e889947 |
|
MD5 | 184e01c90004cd88a76c82b87dc044c5 |
|
BLAKE2b-256 | 5bb6f05169706af9c0426b37e0f33ca8f8fdfbde5cc772bcd751fdd54e12c28e |
Hashes for msgspec-0.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e143da1561b6a766c2fccdb9c487dfcf1d56c8c1b9c8c8c5c3e322f02fbb8c11 |
|
MD5 | a966f16d6c4cb4bdc24418c261c9a29d |
|
BLAKE2b-256 | e692c7b68460bd3d4fa9b5f2bf80c2c8477015a51c3d4d900946472b77027dbb |
Hashes for msgspec-0.13.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 050af5e263eece6a16c07ba651ab83208acccfccc5ab8b47fa6cf99c135f01a9 |
|
MD5 | 17090346183e4d535b590bb1e7b94ca0 |
|
BLAKE2b-256 | d2db896589db9b1d058d08a703ede9f578cb74f881d8c5be37535125fe07693e |
Hashes for msgspec-0.13.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fae7c7e6f7715cebc34ce616b078dc2c021651115915d0c2ea507d9c9074e34d |
|
MD5 | 2c7557b747d6cff38062f8c69a0fbc24 |
|
BLAKE2b-256 | afcf1b54cea58dd653914d9d6d9250997453c4de6c5a609ffc78b9164df98bb4 |
Hashes for msgspec-0.13.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96f7898b4433a2570636cf0659ac7cedd1b753f0a108fa0ff82a813a830c5a98 |
|
MD5 | e3a29256db2df70385553c7eb42fe741 |
|
BLAKE2b-256 | 6bcee6abafd8e5aab02af40816d83b8b666913ad08e0147e79c8f213bffb52ee |
Hashes for msgspec-0.13.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b80b58d8fa70f881701a3bff50661327b4f5a50441d33386fac95a94eb3cad1d |
|
MD5 | 083c29e49344b34af4a64ddcb8dc6a6c |
|
BLAKE2b-256 | 5daddfca504ad5d0c41352b5a9c73161b6583353443c05efbc3bcaf571169985 |
Hashes for msgspec-0.13.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 348415004e907c856e22884485c9f91dc8f39317ce365b0881a08ac35f234afe |
|
MD5 | 498556ed8d1fb6444bf8c8f3e0f98c9f |
|
BLAKE2b-256 | f41b60e942c286ad2dd05f0d5d5f258ae79eda095d57aecc3f1b1a1c339c8f39 |
Hashes for msgspec-0.13.1-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d51cdd579b632e3686c14eee9948aeba056ea969b85b60e09aa9811cea3524cd |
|
MD5 | ced77d30e00e7c18c1dbf54e7fe11c0b |
|
BLAKE2b-256 | e6783fda799546df894a663a2a240123584fc06882d8596c052eba35a59a8894 |
Hashes for msgspec-0.13.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 317ec8e80cf919c42b6defb375e12ad49af649238327d0abaed980c4d72a7bea |
|
MD5 | 5c7ad95fdfc13d5f2eec6f98686042b6 |
|
BLAKE2b-256 | 6528ce2068a5b547e22e0601f35c82664ffac1d8b1899429f2245a5409480c8b |
Hashes for msgspec-0.13.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa7febe37689642a1a2ccdeecf3a8b820ea043cd142438bd0a88714c982555a0 |
|
MD5 | 06f4827908bc7a44de38501799c520bb |
|
BLAKE2b-256 | 463c87f6fa4c29d9607c42d7d9a96738772438f130c50afcc5745f60601e56ee |
Hashes for msgspec-0.13.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e12db829b670159780d4483248c5099b99cc487f3c134f2d3e6ce59fa18ce67 |
|
MD5 | 45c0b528fedb276d2202d48e45aca4f2 |
|
BLAKE2b-256 | bf12cd7150de0d508038d4523607acece0273424f9614fc9335f5ac5c016c18d |
Hashes for msgspec-0.13.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30c80380bfe3a03b2e968f08bdbec8a9fc1619cd2555cc8334774c475296faaa |
|
MD5 | 22b3827f639da1f6591c6820e2021ef9 |
|
BLAKE2b-256 | 31e78d23c75a9682d725713af8d2a7a4d79317c95d7cc0a829de78b126ee7b28 |