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

Uploaded Source

Built Distributions

msgspec-0.4.0-cp39-cp39-win_amd64.whl (179.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

msgspec-0.4.0-cp39-cp39-manylinux2010_x86_64.whl (379.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

msgspec-0.4.0-cp39-cp39-manylinux1_x86_64.whl (379.0 kB view details)

Uploaded CPython 3.9

msgspec-0.4.0-cp39-cp39-macosx_10_9_x86_64.whl (170.8 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

msgspec-0.4.0-cp38-cp38-win_amd64.whl (179.8 kB view details)

Uploaded CPython 3.8 Windows x86-64

msgspec-0.4.0-cp38-cp38-manylinux2010_x86_64.whl (383.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

msgspec-0.4.0-cp38-cp38-manylinux1_x86_64.whl (383.2 kB view details)

Uploaded CPython 3.8

msgspec-0.4.0-cp38-cp38-macosx_10_9_x86_64.whl (171.3 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: msgspec-0.4.0.tar.gz
  • Upload date:
  • Size: 113.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.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.0.tar.gz
Algorithm Hash digest
SHA256 75d05c1d58e46202b8ac4d833532783fa946824e0e04cb6a5650e3cfc9a486ca
MD5 48e2f55e7d4390b8273e25775a5f2248
BLAKE2b-256 0db284549c50e228a060b68d0ec825722d3c322915cf44170960ad2e1764b729

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 179.7 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.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 15e2cb0b713c03751a2d1700835372d7f2c91341fcc52bf6e51059e1c9e08bff
MD5 3a02072c1f6d03b89e1baa3eb2c57af8
BLAKE2b-256 1abd93b379b22c55bdf751cbbde299f60aa0cb1d511141dd234b3a7a422bfe53

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.0-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.0-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 379.0 kB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ 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.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 dfebfee2c5ef2c3fa51ca527a05edda429c0b8572fcc2cfeb1eebc54a4503e06
MD5 f202d7da8db7e7a0b84158d0bed6bbcd
BLAKE2b-256 5ef06d2cf48f223c52474660effb9f2dfe0f9d5d258bc3bd0bc6515e855471ff

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.0-cp39-cp39-manylinux1_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.0-cp39-cp39-manylinux1_x86_64.whl
  • Upload date:
  • Size: 379.0 kB
  • Tags: CPython 3.9
  • 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.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0f7eb74c1bf16e6ba6d88681dabfbf07a41a034dca154c62c82da9c35917253f
MD5 856dd8bf8250d22df0db3651d340f4e8
BLAKE2b-256 c4f3f9f8e773ea82078c1219031170527af95ebc87564725942835c66ed308ea

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.0-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 170.8 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.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 97a1242045a7695c69c3e20fd6815d9634b36e6a5e3ba45d89eba881c20a4808
MD5 784aabab9b78af7ca8885cc309b4c42b
BLAKE2b-256 9a7508b4cb36d9123a98e0f2400b2487d7fd0c5c3b41e2b1731260041510236f

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 179.8 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.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9f0907037a9defbd99d8c708b039de4fa263f9cfbd35b19ba80cd5af822c0b62
MD5 3e459c50b01f55534e481b5c2f597cbc
BLAKE2b-256 60ba858dd8f11f995907751eb349555a5076619bef25bdf22718f15359b0ec4f

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.0-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 383.2 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ 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.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 bd7b83c43b2b13a83fadfc47f1d7f89d669799a5adc86edc625d15f4d1edccac
MD5 c571352e62e12ca99bbd1434fc6a7bf1
BLAKE2b-256 04b1eaa5f32ebc31ec864e1e66d50b77c67f2f5ea464e7e6932769acbb40aa25

See more details on using hashes here.

Provenance

File details

Details for the file msgspec-0.4.0-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: msgspec-0.4.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 383.2 kB
  • Tags: CPython 3.8
  • 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.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 178727faa7fed16abcd03d1c613f315a03c173663bc6f2c88b97b41543b8d4bf
MD5 0a54ea48c9f9dad20f50c0fea530e2c9
BLAKE2b-256 f949dc06567102d1ca2fbbce8dd0ce5aae83cb2c91150657c0c4bbc9794497f1

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 171.3 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.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 546bc9978b3e47031d6c7ec968762d2697e35f3393406217bbfd832a73fbde82
MD5 d64e20814e359eabca8b572efd2a564b
BLAKE2b-256 9ca7e2bfbe6ca3135ce18ec0afe7372f7ff8fd5c0395ff48024b3470752cdba2

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