Skip to main content

A fast and friendly JSON/MessagePack library, with optional schema validation

Project description

github pypi conda

msgspec is a fast and friendly serialization library for Python, supporting both JSON and MessagePack. It integrates well with Python’s type annotations, providing ergonomic (and performant!) schema validation.

Define your message schemas using standard Python type annotations.

>>> from typing import Optional, Set

>>> import msgspec

>>> class User(msgspec.Struct):
...     """A new type describing a User"""
...     name: str
...     groups: Set[str] = set()
...     email: Optional[str] = None

Encode messages as JSON or MessagePack.

>>> 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 types (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.DecodeError: 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-40x faster than alternative libraries.

https://github.com/jcrist/msgspec/raw/master/docs/source/_static/bench-1.png

See the documentation for more information.

LICENSE

New BSD. See the License File.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msgspec-0.4.2.tar.gz (117.2 kB view details)

Uploaded Source

Built Distributions

msgspec-0.4.2-cp310-cp310-win_amd64.whl (188.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

msgspec-0.4.2-cp310-cp310-musllinux_1_1_x86_64.whl (403.7 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

msgspec-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (405.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

msgspec-0.4.2-cp310-cp310-macosx_10_9_x86_64.whl (179.8 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

msgspec-0.4.2-cp39-cp39-win_amd64.whl (188.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

msgspec-0.4.2-cp39-cp39-musllinux_1_1_x86_64.whl (402.5 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

msgspec-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (404.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

msgspec-0.4.2-cp39-cp39-macosx_10_9_x86_64.whl (179.7 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

msgspec-0.4.2-cp38-cp38-win_amd64.whl (188.0 kB view details)

Uploaded CPython 3.8 Windows x86-64

msgspec-0.4.2-cp38-cp38-musllinux_1_1_x86_64.whl (408.8 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

msgspec-0.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (407.1 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

msgspec-0.4.2-cp38-cp38-macosx_10_9_x86_64.whl (180.2 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

Details for the file msgspec-0.4.2.tar.gz.

File metadata

  • Download URL: msgspec-0.4.2.tar.gz
  • Upload date:
  • Size: 117.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2.tar.gz
Algorithm Hash digest
SHA256 e9a46c0304fb0b5ac08e7cecb5281747b3ae4930b52b5ebf0f69400fb5fbcf45
MD5 a80cb71ef7da0c34f9287241f6d1c880
BLAKE2b-256 b6b68f4d21de2e6e25077dc1df67a0308bc6c4843e71b418a66ad8091df52173

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 188.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 353b2532743b5226c89e076eca4d8c2d1935fe45ae1a69a777fbde9b1239041c
MD5 328a1e5324863aaea1387dcfec8a91c7
BLAKE2b-256 08dc1d94fae7bb2462be84b8d8ac7e980e0ec92256a3b6064e6411f3420474c9

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp310-cp310-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 403.7 kB
  • Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 466c80e24234432b229a73ad1f6d48312bb6266d0081e4391c305ee076c064b5
MD5 4bde60d883afcbf3bf810aaca8000521
BLAKE2b-256 b4125e0822ef7f7dceaabf2e07bf97a19b0083af931b32851c65d393930085d0

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 405.3 kB
  • Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c84ec0895ac76fe18776c4e3017d390160a42cb1463da48b6fa27060060c5e7b
MD5 3c8aaa669b2bcb54eb85f5cefe0dbf37
BLAKE2b-256 dfe22615407d811842b58d7e3c920411b149ad20dccc5ecc6d17a7e86e41af4f

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp310-cp310-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 179.8 kB
  • Tags: CPython 3.10, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f02a2f04c6886b29e071fd23ccd7044c8d4d346ee878985986d2400ddf5a4f80
MD5 a30b7014f5dd8e9cca2a8f8b572b39e1
BLAKE2b-256 2d4b2760332f475e34326514eeb7474c091bd090b028d874e51eac8a132bf538

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 188.0 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9fde59f89207fb1898627966e7dde5688fb2a0431451362319019cf0ee355f1e
MD5 6eed2a22c9ac6605f2c661267c88c344
BLAKE2b-256 2f499df41a694679c43707c24153ea397364180af338802f4a6f84e766b867a4

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp39-cp39-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 402.5 kB
  • Tags: CPython 3.9, musllinux: musl 1.1+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 cc8ccdcf0a14d1ca50c14ed31ff951d296ab64f4e4f35d4571ffe160c2e6cdc1
MD5 bd93c9d0b99af9cda73d84a3a60c1ac4
BLAKE2b-256 03017621b250c37b067e88dfaf2882b50f7c49cf593d28e88de2800fb585e6c2

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 404.0 kB
  • Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3494c70e8000c7c2ed40bf24d84d56250fb0f3af1338593e6c8c80208ca4c878
MD5 dffee0f1dae32ddecfc7bdc7e78cb3c6
BLAKE2b-256 9d9da76b0671a296394b36529185e7de12ea14ee4087fbf1b4353a54fa33a9bc

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 179.7 kB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a89cd109190aefdf0f1768bef159f11a60008a31164588ca2d74859d16f8f207
MD5 93ca52219275d78f546a36359b3578ea
BLAKE2b-256 9eb7c8d8299bb619217ed00c716d87b18e00eeb90a67428659767ab7420364bf

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 188.0 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a5a43105134aa0d92c99d1ff30d91a92bb9534924936a26b8401bb0c5742fcd6
MD5 2d5ecc0d9674709549a52747fd6a2f76
BLAKE2b-256 b71100e7b54128db678174a41b4c8a87fe111f76e1d7f6c6dfc3240eb7357f8b

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp38-cp38-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 408.8 kB
  • Tags: CPython 3.8, musllinux: musl 1.1+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 2e16c07140697e99dd1ed73474a8f4a8b747188b75f7028ffe52df59f8622190
MD5 5d653e359050935874c39169dc58bb34
BLAKE2b-256 2c7f1b7b67ae1bb928339380c9b788b3ee8ebbd266e048c7033cb16025bd7815

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 407.1 kB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5343182f691e4a9f650d74229ffb20c98a481dad9cc2c2fbd0e3754d152abad2
MD5 a41457e779ab6f924a7eb93a59e46853
BLAKE2b-256 ef3a37d16b45f48aed7668b2c5fc86ddf67195020e80dd1c34b0ce88cb450627

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.2-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.2-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 180.2 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0bb149b05e63e8505629cbd5f408e604ae45e555535e35541a2dcdaacb99d490
MD5 3a20c5adc38496608aa586b6565fff75
BLAKE2b-256 1aab92040dd773ddf355bf3d5cb3f2f150cd0552944cce5a0d6e27449b18c6cc

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page