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.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c63f9dc8c33ca56903d7957ee7a5d0b3ece6b345b8b10f44b226787a4410c8e1 |
|
MD5 | 9f6efe1c524dd160d828cba0c59603b4 |
|
BLAKE2b-256 | a780991ee00e1b24be0f7bf159e31b89eb596da5a8cecc27f9000e8ecccd5357 |
Hashes for msgspec-0.18.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6bd460e2057a6d9ca6d0e2b848a441c6e30977012d1fca43e4bc1702c9abca5 |
|
MD5 | 6a5cce5b6bc4a2c0f88a8fe228db958e |
|
BLAKE2b-256 | e1debe087e30e3271731bf51ed5de33c57dfdd19f75cf7107c81b5ac84d84cf6 |
Hashes for msgspec-0.18.1-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13980627b9ba28fac2e051757ef5edbe0bebfef411d648e58d2100b86c5eca03 |
|
MD5 | 5de46ba35b92ded47f5ce1c3ada4ad70 |
|
BLAKE2b-256 | 19b132a1f05cac03e6759cf6d7f0b6208686784fc39894b653398746b2be4147 |
Hashes for msgspec-0.18.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 914ab6407fdce1bc795583ba0428f49baf6eedd40df117200ec8fe7666ca2ec4 |
|
MD5 | 298be8c9d5e77b28b33ee6e234aa4c9a |
|
BLAKE2b-256 | 1a89469676081c9c5aaf69a49b456b6f71cb3e5ac1a2f32a251499851aa68bdd |
Hashes for msgspec-0.18.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e96b71e98728830ea3d20acf65969ba7059dfc9e32581039f05e88b8461d98b |
|
MD5 | 08f6d9500c97831c4a2fb79d6f3cfcd7 |
|
BLAKE2b-256 | 7bfc4a078ec6c4661d50aeccd8901c84629c7868b66629b5d59260ffd07142c9 |
Hashes for msgspec-0.18.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 944af5f9ec66de8e21b30ccafdab3e87be11d757ca9304c01e3b2efc373f3293 |
|
MD5 | 379b4d246df12fb09f0c82222951b2fb |
|
BLAKE2b-256 | 72fc1df26eb2e522021e72a0b38474c007c899609a85962b10183850c5aa3851 |
Hashes for msgspec-0.18.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b132ae2691623b3fbee730604671da3bf57ca97d648f1a46a35ea09c6f490fcf |
|
MD5 | 528ac7c0bc07cf89ee102ea4bc40e641 |
|
BLAKE2b-256 | 0dbae84e9fd556276f85471d313db14e0e64536961dfbcef69578e73d05215fb |
Hashes for msgspec-0.18.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36da63a8f64292fff7c814bd3cbbba669f0fa5068c149b4a386dba662ace5621 |
|
MD5 | 8ee609493b1e51e6591ed2966478099a |
|
BLAKE2b-256 | 784eaa69b3e9509524036022ce457c04101ddcd1cec421777dba94b4cb51f848 |
Hashes for msgspec-0.18.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 119ff9d5412eccf53f0d7ab43b587a58f6f806a40ae6b14fd8140173b1cc0285 |
|
MD5 | 3dd1a74a57f92528589f6c1a138e8308 |
|
BLAKE2b-256 | f0dab42fc9f8fd1ea1189a902d6837df253167914350f1d6b0d8a5a0a1fe4774 |
Hashes for msgspec-0.18.1-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52bb422d2b2e80e86d72439edb1a372ff016c0c5d9f44d277b220511486b3f9a |
|
MD5 | 91c12a12dd0ee7533646a5e4aefc1ca2 |
|
BLAKE2b-256 | 0532e9c315d5bdfd9dcfa346c7aab4ff9d1b276146266e0c60d52c176afc71d1 |
Hashes for msgspec-0.18.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebb71f51ca2f62d0d1cf9585f763e3d9fd8a85a0f00d682112916532964692ae |
|
MD5 | 172fc715f286906f857e427744a3a1f9 |
|
BLAKE2b-256 | e54ad1ddfd62ea4c45b4b7e0689f4e24b07652fbe0edae1813a70c44cbafaf24 |
Hashes for msgspec-0.18.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6d21f0da90d1f3e7f65123d375c2b590bfbe3a014920ea812e1a022027b60d3 |
|
MD5 | a94d38b6079badc0a1a77a6c75be5b2b |
|
BLAKE2b-256 | bf1500de80c9ace55b1bd7a72be891e69fabbd688351dd9e12b8718845670ab2 |
Hashes for msgspec-0.18.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3f4a7d5897984f59baf51976682f52f4d2eff88aa64eec8b7f5b80b7a2b6dc5 |
|
MD5 | f5136fe907579d9ac693fbf6accc3b31 |
|
BLAKE2b-256 | da1906def3c370b90dd67905ae3e7b133ea877e49f0bb2cec9dba4a5255058e0 |
Hashes for msgspec-0.18.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 262e5f1a981644f5e9b28a984d6df238eac0ed2c37d788f40abaf10d380b0424 |
|
MD5 | 251b454b0ad68243be27922ea5001358 |
|
BLAKE2b-256 | efc4411d6ad16f9d41d2ebab5c9ed420984b99ecafd45d1dda04d782811b8f5e |
Hashes for msgspec-0.18.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe22658000c165be1055c8df3f7ecc3db85be838d47d1ce1e0526b10747bdf0f |
|
MD5 | 80ea0f18137c2a9235dd418aa96afa77 |
|
BLAKE2b-256 | 0bf468c99aa940a6c5b1972856a76e359186ae22254ae61eaed47ced909aa19d |
Hashes for msgspec-0.18.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0f5070d77658ac953f63114fbaafc6ec967e9e61993ff70cc2432e938a3cf3e |
|
MD5 | 8f21d8708ee19cbd3fc8cbbf08ced0c9 |
|
BLAKE2b-256 | 54033b5abc7c3622e167a61b39124bc1eefc6baa14775de4af667fe2e2d20a57 |
Hashes for msgspec-0.18.1-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bd273e373e220437a22a5ad83a90e3dd648c4e625f48e42e172026de77a3038 |
|
MD5 | 6789d6336844fcb1fcde2579a56c8c6e |
|
BLAKE2b-256 | 3f4b2dbc1731c8ebff0ea13cf2485db5dd67097ae49dec63a6eb2d81d2f59ad2 |
Hashes for msgspec-0.18.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0784a23d1b5b8a6fe4c9f5b9c1779adc5bff4de0fe388545dc2a4f1b5b90e546 |
|
MD5 | 827b6326e9a5a3c0b3f0a44789c5b5ed |
|
BLAKE2b-256 | 5bf8acfceee89fea9f113faf74f10d929dfa2366e0f1c2997a2a6bfbcfa0fb3b |
Hashes for msgspec-0.18.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c63a0f49540e2a888acec8c154066b6ef985813ce27132eb38e1f0c7f49df27 |
|
MD5 | 7fc78d6a37db4678524fb3158f839d1a |
|
BLAKE2b-256 | 1d0fcaa6274dd56c7f9e46d30e922bfb2cc79372ccd349441b05937f03ff27df |
Hashes for msgspec-0.18.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d94555a79013c100b1345e0a5a6d36bfa915e74831e42de3a97cb81313426ea7 |
|
MD5 | cd70938a6376ea344b6d7af96e62324a |
|
BLAKE2b-256 | 79d82cd657a0503c49c40f2afb92c4a63f54e1781f926727c937e255dcbc5339 |
Hashes for msgspec-0.18.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 966ee615b8227c208276863c4269a01dfe8c3b2538b8e1ee33bb01010fe7a3af |
|
MD5 | ca3be4d9cd947273b591552a0757a5c7 |
|
BLAKE2b-256 | e171da0095b50b9a29673c70ef7ca5666898bf6fe44899fe7490d77753b48fdb |
Hashes for msgspec-0.18.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f01fe87b592185a11091206a745fdcba5b40d4c4342d1089959df49f18d6a700 |
|
MD5 | dc5cbd5c61418425f3769b4ff9f45ecf |
|
BLAKE2b-256 | a601427c2fd3ae96fac83bef8dc616880be2a086c37219d7e0a39d0e18015cd9 |
Hashes for msgspec-0.18.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9721948182d471c4f1655634f1970628a7321ec58a2cfb89d35af78c2fc2ebfa |
|
MD5 | ecfb057de085dfe08fdc386788da3392 |
|
BLAKE2b-256 | 1101a3f0a3edd3dce7985cbc8fd986784326447b9d8a1b6cf3dd05b012cf13f2 |
Hashes for msgspec-0.18.1-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c256b21baa1336d651aa9955d69d3f8d0e971d78e0e75fd28a89742af7dcff65 |
|
MD5 | 914044e0257c2b109f25921e22ee0271 |
|
BLAKE2b-256 | c44c4dcf9bca406be6ddcc03bc2ca21482bab46c211064a4dcf8cd3f3eaf06df |
Hashes for msgspec-0.18.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f94eca90ac47a24cb07b3702c863a6b0881830ea02de7ac58a00f778b4b7762b |
|
MD5 | 65e23536cc6c81d804be68bcd24741a0 |
|
BLAKE2b-256 | fabdbb00f129742a28dc8cfa0a28748e8dc069238e6fdffd506977e2fc222d9e |
Hashes for msgspec-0.18.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 597324c72b504f04fb283078b748e664f7f7fc5337bb493e0996511bab895e7e |
|
MD5 | e464cfb94dcf3b9a8924c78760403597 |
|
BLAKE2b-256 | 2e070d09adf190baf27d7e72712a144982864bb4360670901a90f0d01a51a278 |
Hashes for msgspec-0.18.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f936f6ea351c2e8c0d53875a6a71d9887603e3faadbe380172d22283e011f1b3 |
|
MD5 | 74aef14cc48cb06a150d82c8349769bf |
|
BLAKE2b-256 | 0120e5ea9491cfaa4e5f283935fac39705fa416f312201cedaac14ff3f364b5e |
Hashes for msgspec-0.18.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a88d2fb82eb59de0f0f365a27dcea2020440883770b99353e0a3e0aa8ef552a |
|
MD5 | 76b4dbe009f0e03b368919839cb3eabd |
|
BLAKE2b-256 | 4d31a364023d570804a8d119dd78fb52c09705d8d72cd0985eecbaefd394bf19 |