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.17.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79c3ab0bac7dd6492f6c03e347f0e9e5187d9658b8e7c85fdc96dd4820de970b |
|
MD5 | 6d750ef7299b9626d222b6598067033d |
|
BLAKE2b-256 | 8dba32094e7a8a0129eeff6c434d94851353940dda4179e68ff53d4762b3ef44 |
Hashes for msgspec-0.17.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d39dc3a44a479f35afcc21d97c4ea90a385afee0b766c7780ca2bda99480e3c |
|
MD5 | 201cd9ce46d53005c2383bca01ec16a5 |
|
BLAKE2b-256 | 36f735ee594db7b6aec1126210c4daa80554b3acb0b6e3a030e06a8eb8c267cb |
Hashes for msgspec-0.17.0-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86ca5710174970d9aeefc2ced4fcc4a27f5ff065840356cf1c747399aa4ad5a8 |
|
MD5 | c0156e2a54b7289f85a34a9cff114fcf |
|
BLAKE2b-256 | 77b8be04ab99671c80d1d9905a8a050bde5eee4bacda738509fd2bce8ec1768f |
Hashes for msgspec-0.17.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b0c52118aec347d15f75354b2fa27f1c9cd29b6ec12b74ef2ef988a0d702f5d |
|
MD5 | 69dfa2463d3a2d889f36234b241e1d09 |
|
BLAKE2b-256 | 609924d8bbbe107c6d506e3799db7581461953e5f309d339853a7cd84f2e2080 |
Hashes for msgspec-0.17.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 025986a5b1fd81c3dd1bb591bbc01ac03844b57685fcf4a14ed07ae1967b6d03 |
|
MD5 | 97e0443fac08801736e6c6aeea87ecf0 |
|
BLAKE2b-256 | 6ea37e28872da3df0e0f76fdfcb7186db3a264e26c9a3ec86fa30ba63b43406e |
Hashes for msgspec-0.17.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8096ca82e9a3e6fa09106bfac27eb8296c4cead02fdd297bb8af87254e58bad |
|
MD5 | 0471a6690badd31acb2ea685ffb4ebbe |
|
BLAKE2b-256 | ba40dedb81abc00f943c486cf262e91997648e32c1ac3e731a4dfa550cae6b20 |
Hashes for msgspec-0.17.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1a0c8390014ee2b65d0d36d9cc28e74092166e8f44adf3dcb85e1ef25933787 |
|
MD5 | 0448093dafe0f91034021d3e5710fa32 |
|
BLAKE2b-256 | ff91d58e946bb6f144dd1be4250bd7bfb725f343b8037e295bd02ebe69742a08 |
Hashes for msgspec-0.17.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e7e016cd79dc12935b6f5e8ff358ea5908cb84756c84a9fa2f3d8e5405740f3 |
|
MD5 | 16c4148325f9a0d2167b404d3816534b |
|
BLAKE2b-256 | dcd2714b20fde6c58b995f861b6560777c5d37961d3d1656c8796d0afe7848c3 |
Hashes for msgspec-0.17.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98995159d95b4ed65c8cc185bd877fec67f41cb23925237a82efb066ef778fa8 |
|
MD5 | 2d40f1d0db5ed89c369ff1ebf5899632 |
|
BLAKE2b-256 | bd987bc078945d9bcc185b3410fde87f6c2e28b6887564eca946736119f4fdc4 |
Hashes for msgspec-0.17.0-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3adc3f4016aa5ea1bd51c8d5c2a38172f1965dd231e03defed04ff2a0effb361 |
|
MD5 | 6b50be1c7865312f21be15b1475e514e |
|
BLAKE2b-256 | 18fc35d79d3eb4f79824b9e87c6e827656bdc086b227ffadcbdc87ff1071790d |
Hashes for msgspec-0.17.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fb9f68ae2068a96b29d92cc4d142440e616b0a077b53a68b3445c62a2f31edc |
|
MD5 | 42f62fe209e627db11ed98bee5f1b49a |
|
BLAKE2b-256 | fb1d5698cd724735ac2b462ccf2a87c0f0354ee7eeb12d00e2a78fb206682f42 |
Hashes for msgspec-0.17.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cccef9b4216c28f470855540d2649cbcf9eefd74c17984259ed3cbbaaa818c5d |
|
MD5 | 03ad0b84fff9f98a3f07d765639b1d62 |
|
BLAKE2b-256 | 7979a5e16084595651effeac96e1bc0bdd9e780e0e65b9e74664ee99aa1b8c6d |
Hashes for msgspec-0.17.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ab367dd0b8a8c989d295e8ef086305e41a3c73fa3208322da4826f04e24b3c5 |
|
MD5 | 9ae01c0cff8c26c0ca6f4a0dcb992c58 |
|
BLAKE2b-256 | b4d213f7ab5ab6e0c71ad2d46af1e380f4c6f17a69dac9b7c6bb8c4a351c65df |
Hashes for msgspec-0.17.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7bb4fa0021198cc87ece9fd4cbaa7241782f6c1d7b4fab71bb59c30e83c95c8 |
|
MD5 | 0fdad8a5e7081c79c323c8c97a6e53d5 |
|
BLAKE2b-256 | 7a8fa32d5d0b2d6c4f34a70e9ea3bc847bce8b07e05d6750ed61627111d88e0c |
Hashes for msgspec-0.17.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f1b7c9d9f41b8c7724dc206aadbbe84d1641d20a1ff6dab04f0caf2a5bfd438 |
|
MD5 | 68428ea8770f779b42e00795b0beaabb |
|
BLAKE2b-256 | f4b745966b6e3cf682c7526daf50aab0daa7570aa70980e99d4cb9b33118f633 |
Hashes for msgspec-0.17.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59ab1e250a84516413dee3542ff2b43f46fe521adfdc01e628198ce94553ff1e |
|
MD5 | 02a01544836fdc1c9198c076d11f67bd |
|
BLAKE2b-256 | a9e5d857a827c0c330167ac38ecf847f6c6aa382d50c31dc16d71c6c4391366c |
Hashes for msgspec-0.17.0-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5e49b9a302acee0808466b1af31c675d7cf8fd5ee78874109b5a44cb40c67e8 |
|
MD5 | cb412cca482f1de7199362b7bd290381 |
|
BLAKE2b-256 | 1500396dc9253dd2f4e3daeed104d90fd8dc904c3e5806d71ce9dd70b340d5c3 |
Hashes for msgspec-0.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aded9cd083d3a966610b6b01787106fa6aab495486420163a7b872704767da0 |
|
MD5 | 95a495a634241caf15b89458c86a3feb |
|
BLAKE2b-256 | b3719218e0d72a4e7218eab414b21c5b2a8e00d3618af7c6c24ce2321b50f9bb |
Hashes for msgspec-0.17.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce2a7da8669887b17bed92d3143aa0cc936fabdadcdd43c9ed09cfaca71a2fc5 |
|
MD5 | e6c06d42831816c73e6bc7a1e9ff8754 |
|
BLAKE2b-256 | 177fcb3a29fa574234eb01790ddd53b490be801e4dc18e25d46a83c470ce395b |
Hashes for msgspec-0.17.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de90a979e48e95ab6175a59f3f256a88984ff599edd5d3948993dfd6ecff83d0 |
|
MD5 | 8601b48cbcfa08c9ddb40685371ac56e |
|
BLAKE2b-256 | ae9ee4310578ce506907f68e1679480ca922a8e1f65e9930c3d8517f5218caa7 |
Hashes for msgspec-0.17.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 556413e59a8017c12a177218b3d3c16bb7217dc0371853b61e4c98df19515088 |
|
MD5 | 6a8100b1b9bb755f07b7f3db3ac6599e |
|
BLAKE2b-256 | 25beac9697c52dfbeb896efcc3b901ed4bc1a32a3f498087d5ed2d2eb2cff768 |
Hashes for msgspec-0.17.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc3f9fbb3d127a0c9734d43870b565a809c1fe2a0913d04170fa1222dfb131dc |
|
MD5 | 018ca26f271ad9687bc2bbaca32c0061 |
|
BLAKE2b-256 | 0880d280ad99ee9347e725b9b443e0032f1bf73b5ffb83301eb9a5a7b5ab9491 |
Hashes for msgspec-0.17.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23581f8c1ffa488c2c3c78359868ee408528dad5e02af94e87e8d4773d118399 |
|
MD5 | 424cfc5aedcf1a6195f8ef9ad3dd01cc |
|
BLAKE2b-256 | b26989cc7b6b473eb27861f1547a076d60884a52f58e5e69d37e279e606cc91f |
Hashes for msgspec-0.17.0-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 396908a124f633c3e267ec01b5bffdbefd592b15ddfda63c1af798e0102c35c8 |
|
MD5 | ffd8ca76cbf99e7bedade70d093f94b2 |
|
BLAKE2b-256 | 29e2ba0a92d19034ef8296bd3c4da9c20f389cb6fbbd3514f6456c6361c16a2b |
Hashes for msgspec-0.17.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93fcff4e7923050cbfb3be8b4763a95862c3bf35d198684f3ebc3c486a1f66a5 |
|
MD5 | ccd75e377590d0a2bb8dbec7b0198593 |
|
BLAKE2b-256 | fe8ece15af3900660c3f7e68067dd2dbb9aa3ed187099acea83f900b69c898f0 |
Hashes for msgspec-0.17.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51aec8ae03348525749f4eff4ed59fc7369383877ad65e0f00de3e357c4ecfa6 |
|
MD5 | bfdd7b0d613a4b0b7c4fa9ce6431e8e6 |
|
BLAKE2b-256 | 17fde694015c0df662bd217f7a2f2db1d2d0521d36435352cf2de73bb962fe5d |
Hashes for msgspec-0.17.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80021321fea9be9e03c7675f6bdce06d9c91dbfb4aec78044cd243491ed49fa9 |
|
MD5 | 218490a21cdfe4aebe53efcfcd365c79 |
|
BLAKE2b-256 | c13f8eb65c82f39698e5ba2967872e04e058c18435832fb77db0fc24488c8154 |
Hashes for msgspec-0.17.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 832e841d17bc2b4d74eee6aa16c818074cc9104c9a79466dbd49162600af8e9b |
|
MD5 | fb507d55f6ffb782af83282aec84fb9d |
|
BLAKE2b-256 | 1685d81c9aad934331210f87c7a5a233498eb71f9dc4fcccf04395f3dc901a43 |