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.5.0.tar.gz (122.9 kB view details)

Uploaded Source

Built Distributions

msgspec-0.5.0-cp310-cp310-win_amd64.whl (199.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

msgspec-0.5.0-cp310-cp310-musllinux_1_1_x86_64.whl (433.5 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

msgspec-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (434.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

msgspec-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl (191.2 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

msgspec-0.5.0-cp39-cp39-win_amd64.whl (199.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

msgspec-0.5.0-cp39-cp39-musllinux_1_1_x86_64.whl (432.3 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

msgspec-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (433.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

msgspec-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl (191.0 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

msgspec-0.5.0-cp38-cp38-win_amd64.whl (199.1 kB view details)

Uploaded CPython 3.8 Windows x86-64

msgspec-0.5.0-cp38-cp38-musllinux_1_1_x86_64.whl (437.8 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

msgspec-0.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (436.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

msgspec-0.5.0-cp38-cp38-macosx_10_9_x86_64.whl (191.6 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: msgspec-0.5.0.tar.gz
  • Upload date:
  • Size: 122.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.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.5.0.tar.gz
Algorithm Hash digest
SHA256 f6ca133b6ff16927d627de2f8782649c81c5b4570c1d40a49eb19ee02a7d2016
MD5 00b7c93bf13765c96cb08eab59cec8c4
BLAKE2b-256 f77d7a0e385a85facaaadfde811158ce0f00cdd3cf8783317e1fdfd7e868d8e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 199.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/33.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.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6149813a96a1f30b13d79b3cbc13cb86c3afee0bdbe6562ee56ed38783d14243
MD5 5807bb4b6270341c287246d07ca39aa0
BLAKE2b-256 e81765d3ee747aa2bb544ecb0788cca59cdda24641b046c3c2da5aba228fd1d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp310-cp310-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 433.5 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/33.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.5.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 fa35f58bafc2d3f2b606d78058c8eb948e1dbc6f0e60eb52bae57ae5a981a80c
MD5 295284f895ae0fbb0234e84dbd53da81
BLAKE2b-256 588b6113f52614f889ac38f1d412ab79533bf9ae07a92deba0034f2b6d4b0f85

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 434.4 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/33.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.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8c9fa65ddcc1b18437b00e3bd4941d67271798023e5128e0e2b75a023a723379
MD5 686d2241363aab380249f961b5fdfb68
BLAKE2b-256 55c3a08f38b2bc6f6272970b41a8563fdf5af847ee2a8690f19a4da6f540a8fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 191.2 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/33.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.5.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1f0cb6ded70071dee349435362497f463fab90065efc46c3420d96584d85b233
MD5 833ead5b203cf37e7b425b062f16dfae
BLAKE2b-256 51a6365d5d43789ee8ec7587aaef3e03d17ea4392341061ec3491d3d71d91f28

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 199.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/33.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.5.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1549c478e7bf40fe9664a24fd06517b8f323752bf7cd67d2f65f19870caf208d
MD5 72a9839d17f28259551fb60d60286b8d
BLAKE2b-256 bed6b8e40ca47752eb4721a312b5d3c189fd6d9e747f0f4d2070152078b336f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp39-cp39-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 432.3 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/33.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.5.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 2bb3b44fd81d7ea792a91f55d48122acd4fd451003ab39e261a19521861ea1ab
MD5 810de09a45c1e1dc5a2f6467b432ab8f
BLAKE2b-256 0bbb691d2e5cd4ddf03fc0de548b7589a6241163fee5bef99d233b8363136ff2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 433.5 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/33.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.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 78c60ba92fa1bf426c1cde099e6222750406a0caaf5c9d127a396b5802b6a79b
MD5 018e5df3b07b38f96e68c06a489d5079
BLAKE2b-256 20b24929794f246065cb30e435220950601597c0853f70f986156aee1d555120

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 191.0 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/33.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.5.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3fca19f575b67f035c6a3c264d47fcea12799313b4fae479008dc1723b1327b5
MD5 d40790353f38f3cee75b5454a1170752
BLAKE2b-256 99987c0a3eceff9fc179cdeb81742d65e69ebd17fbffd9e323ba0c93a7036055

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 199.1 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/33.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.5.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9a0f483c7bdabe880d758ecaa816d24fecbd763aaef951156ed22f9b35998a47
MD5 53cce29ef49c331387033ce7e1b1d9bf
BLAKE2b-256 dab09239f2a638564e359a64eb3f6f4eea5b43fe27704045dd1bfc63e9183226

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp38-cp38-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 437.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/33.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.5.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6bda286fb9f4fbaeed7a46a1f6280a50e47b80efe67adaa68d6fde67aa588524
MD5 f60e0634d0f721f873598e1c710b5bb8
BLAKE2b-256 0fec4d0989099302e045b40a7fde1aff076b60e93fb31e5e7bfd95675fc367b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 436.8 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/33.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.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c3b671b32b15c401b2f6684e12677956c4617491a5f12ab49acd25456d82c0a6
MD5 46be2d4fc9750dd43612ab9cccf5b8e4
BLAKE2b-256 91ad8ffc3b54635b7a10c8c361e79abf160c90b73307575552e0fb9d79fdc84a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.5.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 191.6 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/33.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.5.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e36edf09256e54477e74378b39c4ba01ab2dea9753e7539ddfb8befb49d53dae
MD5 70cd710c4b616931f9660e3def8def88
BLAKE2b-256 bba01885592815973e6caa2d3319314d406799579ea5a6c40d44eb11c97eae60

See more details on using hashes here.

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