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.14.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02e5f46b3d03a0b08bbfcd0bad9595dc732b505556cd2a7f9f01ba5b3355ae7c |
|
MD5 | c626feb69bc79dda3b4679c89881ebad |
|
BLAKE2b-256 | 09e276caf1e2920d2260597a6734c0b5bf36316d040fb8e0a13ce418f47f4a69 |
Hashes for msgspec-0.14.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21ee98a51930ccf57a6b16b55a1049d8cc358315196aae6c621f3d93cc25714d |
|
MD5 | ab6054f1b6133a297db7b71718470da2 |
|
BLAKE2b-256 | 7392393e1de3e0f85686e6afc2dc317e0a76eb91f6765516023065b991b2f718 |
Hashes for msgspec-0.14.0-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86da8fdc94f0a38c188cb9f896174e0ba9bb474eb6b4c2937ef96075dcc76e52 |
|
MD5 | b3ad4c548f53c90a14d1f42ab1d04856 |
|
BLAKE2b-256 | 27a4d984a7e7d78c72519c34d85005605e498f0c5e0c455a5228a9a51dac035a |
Hashes for msgspec-0.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89f5c94f72bed3d3b6e9252b903391fb584759d1cecb607b4788392ad264fad2 |
|
MD5 | e1b0b0a0768fe3888723805b969da848 |
|
BLAKE2b-256 | 0ecc098e4445e0a77d41f7434b1fea526cfdc18521006eb872dfad691647464d |
Hashes for msgspec-0.14.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e29c330a183d2a015ee0edf8d4799540aec0ab9ffb14426c637cf1f121ed652 |
|
MD5 | 5f710f1a25de636bf6f4a32fff2b639a |
|
BLAKE2b-256 | cdbc88add919133e8e3d4c5ac3eab25d3fda70d227472bb9208232dcc12aedfd |
Hashes for msgspec-0.14.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e46843d258c3043c4807649710c20a34c37b9b91c6cd78684575f78283ec873 |
|
MD5 | 1f9a34af0d59b53ba10786aa98aba6f6 |
|
BLAKE2b-256 | 68b9dff623dd49799a33cfb99d7cec3b6b7c1872d9414ce6925fcc9c5eece548 |
Hashes for msgspec-0.14.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8699dbcc1eef9496bbc0d098667a0fc19041ba1c3a74af532244a5048db19ab |
|
MD5 | ac56a251639cf0f4382812dcf3c48196 |
|
BLAKE2b-256 | 20abd9970ac4666e61d640c3da278957fc12190768c8c6e13488f2681dbcfa96 |
Hashes for msgspec-0.14.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8cca6587fe94b6998151d15c05bf97bbbd4ab47ebf57b18ed49d20bb2a1713d |
|
MD5 | 41356ed004d576f7d7297d9b68675797 |
|
BLAKE2b-256 | 32716d61486fbbc128d932fe693e6017e1a22d42a110594b5a82b6325037cbfd |
Hashes for msgspec-0.14.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18a5724546fd883a575b46e26fd81d37b47b66278e89e9610a5c87aea4fdebfc |
|
MD5 | 37b62689b83a38635a51590a6c32b975 |
|
BLAKE2b-256 | 8a57fea68040829bd8473406aca81493557460cd725ccc7d265bd947781eb43a |
Hashes for msgspec-0.14.0-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7a89677eae142c155c51d87c1df73fc5333db7cff1e08af8976aeaab2c81114 |
|
MD5 | ee527262868ca50a9c1242d2f42b9941 |
|
BLAKE2b-256 | bd9a94108315cf995ce91b71baa71d2986aaf79ced79f251250e4ca38b37007a |
Hashes for msgspec-0.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a53047a5bbeb9f04e78990a2d17a2735c15744be13246e2c3a625db0941887d |
|
MD5 | cee69ba6e5eed52bf7924dc69be16132 |
|
BLAKE2b-256 | dc0a1a17d1a5acb8da83f51b4e6568642ac2fbddefbe052a3670a95f6a95a688 |
Hashes for msgspec-0.14.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e497794d5df290911fa6b38682788e3ebee48ec9ed33b0ef5f1f9c2ac7011f45 |
|
MD5 | 9c0fa9abc53fd6ac91aebaef14258b5b |
|
BLAKE2b-256 | c7b08e5efe8f0705c0967fd09cea8cb07915a31f3347ac405b35d760b6d03e36 |
Hashes for msgspec-0.14.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e06dc68ccd9a456f21abf0dbcbe3d1ed00aa53f39fd01eb1f226e2e98d6e49f |
|
MD5 | a8c743880575518019e55cd7d44a8536 |
|
BLAKE2b-256 | f018fc33fadc9bd518119ff9291a0c696847ed3b3b7737e57de9a14069b79ee1 |
Hashes for msgspec-0.14.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f001981317161efd31703dfe2dbccb65feba2222baedf1e1d0d3fbc4e4481d4a |
|
MD5 | 88f7cb2361ef10ff8a0a747e7809ba42 |
|
BLAKE2b-256 | 96e4a5b9ba8bbc4f404ac149b49d7c9d0bb4302c7b64a9a668f8793d6b721603 |
Hashes for msgspec-0.14.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0f178d36eb91ba99003bd5e0bae4c1cb834f0d86b4ae9b5a8e88d4ef544ba86 |
|
MD5 | 64cf57890b26bcfdd9f1840b6f59a906 |
|
BLAKE2b-256 | 4ba0c1485e570e2f6c0458560fbacedc225d48eb6a7c0495fefb5db29075e8c3 |
Hashes for msgspec-0.14.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a15d07d9daeb7daad32b19c194913452ba14748a37d230bcee45e118767b7b8e |
|
MD5 | 098b6758705810a57b5533a1c51e8a02 |
|
BLAKE2b-256 | ff1d4f0bb8ee69cc9dfe2cb8b79b424defe756838692eee42bb1550da96a02e1 |
Hashes for msgspec-0.14.0-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8fee0ffa0753f632cd94fa304a2e9ca9c92f9695fdb2ea160ac048dc278d008 |
|
MD5 | 272b4f3797b494ac3452b984fe18fd6a |
|
BLAKE2b-256 | 5d8c0e59d2b667d4ac22431b5710cef7e1cf1cd1a58154f98aef9c58d304ff36 |
Hashes for msgspec-0.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d8b4969739f60fc3751e1c73c4cf31f061654a00b452675cbb22ea99f06c2df |
|
MD5 | 744ce5f72a184cb14942d40dd40fa222 |
|
BLAKE2b-256 | 448dba056bb879e464ea5c8075ea161fef2a5c03266cfd377d294137ad04feea |
Hashes for msgspec-0.14.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15d910a223737735196297dd4d26b54679e2ac2b95beaef3837ff918a13be7db |
|
MD5 | ac3749b865c6753992fa50f09fd0ad2f |
|
BLAKE2b-256 | 416755bb628c55761d8a0fbc311daacea8afd02bbef7f82ec4d9528f047d6733 |
Hashes for msgspec-0.14.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1431df375e36f678d0d9b802c1792c904e70c315002c08ecf85ff1007cabcdb7 |
|
MD5 | 72f1dd96bedf897b9b01780eba0a83ef |
|
BLAKE2b-256 | 01c22af9c08b92e7e8b72c39bb5b653a8db2ebc619bc1afb5d175cd6f8658e6a |
Hashes for msgspec-0.14.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b4798f9ff27aea6cc4edf072ec735c95e42a9ba499fef0120f09c52dfc469cd |
|
MD5 | fb9879bfa1639dd6cb1b4310e97d0328 |
|
BLAKE2b-256 | df49c1356423cbdab84a431d1f23f0b706a9fb0737ffbf5174897fcb392b80b5 |
Hashes for msgspec-0.14.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8da19d4a46f3fde25e2c32e798785716df873d29a4ca763d8becf3715c20efc |
|
MD5 | e5da919e0e89ec0c23f078024360ec69 |
|
BLAKE2b-256 | 033e5339f8fa6415b8052aa622fcb7d4b7a031cfd3f176ea8c2af6bef0371c8b |
Hashes for msgspec-0.14.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3d0433dbf09a1ed8b197d0809d513c5f11de62cca50b1b9ac2b6d72e602ab4e |
|
MD5 | df66555d3c8190df2c26ca4553990a61 |
|
BLAKE2b-256 | ecb34169137fbe08907f9eb0b84829b9112678992a7f28f0bd8316b548803bd3 |
Hashes for msgspec-0.14.0-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f972fc150f5a397e4df9aa369a21b3cc733d588855aa27d603977463cd50c983 |
|
MD5 | 5f4f04b3f4285405b57c1e661b386399 |
|
BLAKE2b-256 | d6fb99ab24fb2dd160cb827003f76c31df534124100a7e4ade04e0477762ef6c |
Hashes for msgspec-0.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6866a184a408d40d1098ff922b9592beca53ae9b90495f34ebb78a2d23a47dac |
|
MD5 | 65c63a49d85265377883ff308d6f976c |
|
BLAKE2b-256 | e04ab731a1b83e52d6c8b1fdcbc8b6b825be701050fbab7377c41818c80ffef6 |
Hashes for msgspec-0.14.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b59025a865120703a3e51da79f7ff50aee674003317d3046352f806fd5e7d28 |
|
MD5 | b1fa3da54f61b669fdb141d4003b1a46 |
|
BLAKE2b-256 | 3f9e7bd0f5087cfc91d609573cc61fa0d8806eb171d909b107efa72205279da9 |
Hashes for msgspec-0.14.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f674712b5f75bfbb45328b3953dff8df1ff50acc16468d7a7916424266af9cf5 |
|
MD5 | 41c2bfe67a31dc74619f498dd5bfa87e |
|
BLAKE2b-256 | 1e2eeb2fe33dcc5ec407b35bf5eb965408d1c543993286c2089fa68a57490093 |
Hashes for msgspec-0.14.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7de7ae6d69a2d08bacab29727e594220788c5a9ae6b0bd1fddd966fa70b8cc1c |
|
MD5 | 0b1b66f15647413857cafa810ed257d3 |
|
BLAKE2b-256 | 78f5cbbf6a5d316f0637b745260d2cd92fdd4543335ecde1f9873d05d844aea3 |