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 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 5-60x 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.6-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1003c20bfe9c6114cc16ea5db9c5466e49fae3d7f5e2e59cb70693190ad34da0 |
|
MD5 | 8ea9204cd4f710318d472280025dfc4d |
|
BLAKE2b-256 | 3f7630d8f152299f65c85c46a2cbeaf95ad1d18516b5ce730acdaef696d4cfe6 |
Hashes for msgspec-0.18.6-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d70cb3d00d9f4de14d0b31d38dfe60c88ae16f3182988246a9861259c6722af6 |
|
MD5 | 02e0e5645e8eeaf6e07600a3ec7e42b9 |
|
BLAKE2b-256 | ce0bd4cc1b09f8dfcc6cc4cc9739c13a86e093fe70257b941ea9feb15df22996 |
Hashes for msgspec-0.18.6-cp312-cp312-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db1d8626748fa5d29bbd15da58b2d73af25b10aa98abf85aab8028119188ed57 |
|
MD5 | 12d7f3d3e1b1a701abee59c3aa05002c |
|
BLAKE2b-256 | c190f5b3a788c4b3d92190e3345d1afa3dd107d5f16b8194e1f61b72582ee9bd |
Hashes for msgspec-0.18.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad237100393f637b297926cae1868b0d500f764ccd2f0623a380e2bcfb2809ca |
|
MD5 | 7f7a8c7e3b0b5a9e29ab22c65de6d4ab |
|
BLAKE2b-256 | 7316dfef780ced7d690dd5497846ed242ef3e27e319d59d1ddaae816a4f2c15e |
Hashes for msgspec-0.18.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e97dec6932ad5e3ee1e3c14718638ba333befc45e0661caa57033cd4cc489466 |
|
MD5 | 67008e3734c2d74ca4eb85f4bb6161a0 |
|
BLAKE2b-256 | 0ef2f864ed36a8a62c26b57c3e08d212bd8f3d12a3ca3ef64600be5452aa3c82 |
Hashes for msgspec-0.18.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce13981bfa06f5eb126a3a5a38b1976bddb49a36e4f46d8e6edecf33ccf11df1 |
|
MD5 | 6011d74cfedbcabf6e5967353f0039fa |
|
BLAKE2b-256 | d79a235d2dbab078a0b8e6f338205dc59be0b027ce000554ee6a9c41b19339e5 |
Hashes for msgspec-0.18.6-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d86f5071fe33e19500920333c11e2267a31942d18fed4d9de5bc2fbab267d28c |
|
MD5 | 0e7395c7c7800869f2c284e22b198f3f |
|
BLAKE2b-256 | 1db5c8fbf1db814eb29eda402952374b594b2559419ba7ec6d0997a9e5687530 |
Hashes for msgspec-0.18.6-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41cf758d3f40428c235c0f27bc6f322d43063bc32da7b9643e3f805c21ed57b4 |
|
MD5 | 040505da734eadac7a4ba1bd2a0163dd |
|
BLAKE2b-256 | 51c60a8ae23c91ba1e6d58ddb089bba4ce8dad5815411b4a2bb40a5f15d2ab73 |
Hashes for msgspec-0.18.6-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0feb7a03d971c1c0353de1a8fe30bb6579c2dc5ccf29b5f7c7ab01172010492 |
|
MD5 | c83c41a6b2a176f9f5c1cf04d7266808 |
|
BLAKE2b-256 | 595ac2aeeefd78946713047637f0c422c0b8b31182eb9bbed0068e906cc8aca0 |
Hashes for msgspec-0.18.6-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37f67c1d81272131895bb20d388dd8d341390acd0e192a55ab02d4d6468b434c |
|
MD5 | ebfe06c9c65dba0c279eb8838768541d |
|
BLAKE2b-256 | 29d42fb2d40b3bde566fd14bf02bf503eea20a912a02cdf7ff100629906c9094 |
Hashes for msgspec-0.18.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3b524df6ea9998bbc99ea6ee4d0276a101bcc1aa8d14887bb823914d9f60d07 |
|
MD5 | 1d13377c96d87101b1615e8591e09ee4 |
|
BLAKE2b-256 | 6a731b2f991dc26899d2f999c938cbc82c858b3cb7e3ccaad317b32760dbe1da |
Hashes for msgspec-0.18.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3232fabacef86fe8323cecbe99abbc5c02f7698e3f5f2e248e3480b66a3596b |
|
MD5 | 4cdd7d85bf0ab748ca3ba6f15e608da1 |
|
BLAKE2b-256 | 0de65dd960a7678cbaf90dc910611a0e700775ee341876f029c3c987122afe84 |
Hashes for msgspec-0.18.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5351afb216b743df4b6b147691523697ff3a2fc5f3d54f771e91219f5c23aaa |
|
MD5 | e812b982192b1cf007a4f7c36de8afb3 |
|
BLAKE2b-256 | 258c75bfafb040934dd3eb46234a2bd4d8fcc7b646f77440866f954b60e0886b |
Hashes for msgspec-0.18.6-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e77e56ffe2701e83a96e35770c6adb655ffc074d530018d1b584a8e635b4f36f |
|
MD5 | 7f9c9111e9438814c5612e1d41634587 |
|
BLAKE2b-256 | 1520278def3822dec807be1e2a734ba9547500ff06667be9dda00ab5d277d605 |
Hashes for msgspec-0.18.6-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fda4c357145cf0b760000c4ad597e19b53adf01382b711f281720a10a0fe72b7 |
|
MD5 | 7a3543029bb708bc44e9aed602b52521 |
|
BLAKE2b-256 | 7dd194919c9b837fc9a0e9dfc1b598a50298bd194146e7bc7d3f42f18826e9f6 |
Hashes for msgspec-0.18.6-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ac4dd63fd5309dd42a8c8c36c1563531069152be7819518be0a9d03be9788e4 |
|
MD5 | 390cbd2306eb900701eed0dc289bc2d7 |
|
BLAKE2b-256 | 32f157187427a5a3379cb74aaae753314f9dcde14c259552ec0cb44bcf18db49 |
Hashes for msgspec-0.18.6-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6896f4cd5b4b7d688018805520769a8446df911eb93b421c6c68155cdf9dd5a |
|
MD5 | b1baf1c64dd3a2750010e1327317bf82 |
|
BLAKE2b-256 | c7e44bb5bcd89a74bbb246a21687dd62923c43007e28ad17db24ff58653456cb |
Hashes for msgspec-0.18.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a4df891676d9c28a67c2cc39947c33de516335680d1316a89e8f7218660410 |
|
MD5 | 4e5911918607819327e34efe7e8073fa |
|
BLAKE2b-256 | 231f10f2bf07f8fcdc3b0c7bf1bfefdd28bd0353df9290c84e4b3ad8e93e0115 |
Hashes for msgspec-0.18.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06acbd6edf175bee0e36295d6b0302c6de3aaf61246b46f9549ca0041a9d7177 |
|
MD5 | a00d4ee0b6996c4546a23aa4115a187b |
|
BLAKE2b-256 | 980740bcd501d0f4e76694ca04a11689f3e06d9ef7a31d74e493a2cc34cd9198 |
Hashes for msgspec-0.18.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a76b60e501b3932782a9da039bd1cd552b7d8dec54ce38332b87136c64852dd |
|
MD5 | 9828d6d58cfe712a3952f220c87f85b5 |
|
BLAKE2b-256 | d4b8d00d7d03bba8b4eb0bbfdeb6c047163877b2916995f837113d273fd3b774 |
Hashes for msgspec-0.18.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77f30b0234eceeff0f651119b9821ce80949b4d667ad38f3bfed0d0ebf9d6d8f |
|
MD5 | 04f81f022e85bbbb0ef73c967584a943 |
|
BLAKE2b-256 | 495434c2b70e0d42d876c04f6436c80777d786f25c7536830db5e4ec1aef8788 |
Hashes for msgspec-0.18.6-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5c390b0b0b7da879520d4ae26044d74aeee5144f83087eb7842ba59c02bc090 |
|
MD5 | 24a9d9cb2a5153b8c01aae5c9d87961b |
|
BLAKE2b-256 | cdb2283d010db6836db2fe059f7ee3c13823927229975ffbe1edcbeded85a556 |
Hashes for msgspec-0.18.6-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c61ee4d3be03ea9cd089f7c8e36158786cd06e51fbb62529276452bbf2d52ece |
|
MD5 | e653a78467360250c22c19eb976c44ab |
|
BLAKE2b-256 | 67154b8e28bfd836cd0dbf7ac8feb52dc440d9ed028b798090b931aa6fac9636 |
Hashes for msgspec-0.18.6-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e24539b25c85c8f0597274f11061c102ad6b0c56af053373ba4629772b407be |
|
MD5 | 63011b122a4aabac1a90a11aeb91f005 |
|
BLAKE2b-256 | 70039a16fac8e3de1b1aa30e22db8a38710cbacdb1f25c54dd2fcc0c0fb10585 |
Hashes for msgspec-0.18.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aa85198f8f154cf35d6f979998f6dadd3dc46a8a8c714632f53f5d65b315c07 |
|
MD5 | c0ea484fde3845a1d6238339ad977af0 |
|
BLAKE2b-256 | b7ee9967075f4ea0ca3e841e1b98f0f65a6033c464e3542fe594e2e6dad10029 |
Hashes for msgspec-0.18.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7481355a1adcf1f08dedd9311193c674ffb8bf7b79314b4314752b89a2cf7f1c |
|
MD5 | b3b3931bd9ba60e64ab198a652c6b1e5 |
|
BLAKE2b-256 | 87fc1e06294be19595fc72e99957bf191a8a51be88487e280841ac5925069537 |
Hashes for msgspec-0.18.6-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd62e5818731a66aaa8e9b0a1e5543dc979a46278da01e85c3c9a1a4f047ef7e |
|
MD5 | c69093ee88bc8717ed3a73f2f2406319 |
|
BLAKE2b-256 | ddb62a78cdd1ef872ad96c509fc4d732ffd86903861c9b4e0a47c85d0b37b0e3 |
Hashes for msgspec-0.18.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 974d3520fcc6b824a6dedbdf2b411df31a73e6e7414301abac62e6b8d03791b4 |
|
MD5 | 191fee898472e5fe80d8697b5651120d |
|
BLAKE2b-256 | cc0154e711813b04a668cbc6467e20ea747aec1aaf2c9afd83ed470d774d22d0 |
Hashes for msgspec-0.18.6-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fac5834e14ac4da1fca373753e0c4ec9c8069d1fe5f534fa5208453b6065d5be |
|
MD5 | 29466b200192f754a430aa77d911e79e |
|
BLAKE2b-256 | 1eb11a92bf0dd6354316c9c3a0e6d1123873bb6f21efdb497980e71e843d2f85 |
Hashes for msgspec-0.18.6-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc001cf39becf8d2dcd3f413a4797c55009b3a3cdbf78a8bf5a7ca8fdb76032c |
|
MD5 | 9c6e92f3722298efc363a0b2f80ac934 |
|
BLAKE2b-256 | 13cd29b0de4e0e4a517fff7161fba034df19c45a5a0ef63b728d0e74dba4911d |
Hashes for msgspec-0.18.6-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9080eb12b8f59e177bd1eb5c21e24dd2ba2fa88a1dbc9a98e05ad7779b54c681 |
|
MD5 | 3f2eed380ae2515c81d3c846b24d3bca |
|
BLAKE2b-256 | 8598da3ad36c242fdf0e6cd9d63e5d47ca53577f23c180ef040f4b3aefb5b88e |
Hashes for msgspec-0.18.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8355b55c80ac3e04885d72db515817d9fbb0def3bab936bba104e99ad22cf46 |
|
MD5 | c6ddabef2218cabfab9edf2ab70b04bf |
|
BLAKE2b-256 | 21e01dff019ae22b7d47782d6f1180760828bc96fde368aea983d8e5d872833a |
Hashes for msgspec-0.18.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46eb2f6b22b0e61c137e65795b97dc515860bf6ec761d8fb65fdb62aa094ba61 |
|
MD5 | 489b7165435422ef2e274cae65ec90f0 |
|
BLAKE2b-256 | f07700e1e55607de1092dded768eae746cfdfd6f5aca4ad52b9bb11c3e3b1153 |
Hashes for msgspec-0.18.6-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da21f804c1a1471f26d32b5d9bc0480450ea77fbb8d9db431463ab64aaac2cf |
|
MD5 | 393f01cfc3b3990bd5ccae49d4949416 |
|
BLAKE2b-256 | 866f1da53a2ba5f312c3dca9e5f38912732e77f996a22945c8d62df7617c4733 |
Hashes for msgspec-0.18.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7d9faed6dfff654a9ca7d9b0068456517f63dbc3aa704a527f493b9200b210a |
|
MD5 | f29c64f4127c8dc7b3df4e667dfaf46c |
|
BLAKE2b-256 | 5b2b262847e614393f265f00b8096d8f71871b27cb71f68f1250a9eac93cb1bc |