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

Uploaded Source

Built Distributions

msgspec-0.4.1-cp39-cp39-win_amd64.whl (187.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

msgspec-0.4.1-cp39-cp39-manylinux2010_x86_64.whl (403.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

msgspec-0.4.1-cp39-cp39-manylinux1_x86_64.whl (403.2 kB view details)

Uploaded CPython 3.9

msgspec-0.4.1-cp39-cp39-macosx_10_9_x86_64.whl (179.5 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

msgspec-0.4.1-cp38-cp38-win_amd64.whl (187.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

msgspec-0.4.1-cp38-cp38-manylinux2010_x86_64.whl (408.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

msgspec-0.4.1-cp38-cp38-manylinux1_x86_64.whl (408.5 kB view details)

Uploaded CPython 3.8

msgspec-0.4.1-cp38-cp38-macosx_10_9_x86_64.whl (180.0 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: msgspec-0.4.1.tar.gz
  • Upload date:
  • Size: 116.9 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.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.1.tar.gz
Algorithm Hash digest
SHA256 850fe1e72ec5362b06b2053f860e1c4552fa6402ee80a93c496f357843a3b77f
MD5 05b7d0a362d8dff397ee3ef62851c847
BLAKE2b-256 98bddc78b0cef93bdb7c418c3fe8c66bea6ede3f0a27105b2b2d74f3eec2fb9b

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 187.8 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.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 331d94fb7c219853647335493617ef1eee8a40a2a5edb84392561e0bdf31b3f0
MD5 5ebc9c957ebd0fadddc9438976855bc9
BLAKE2b-256 a7009150584206066f108c92df81b85a62e58b1be1dfab3963978201039ee7ca

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.1-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 403.2 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.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ebfb53ad5fc6a0665101d3d18c63a6adb1c9ec7ee0d59378f1aca8c36750b533
MD5 5c393c5ca6c4349f29340903799c3221
BLAKE2b-256 851df457b79ac957c9e7288526a9aeaf3498fdf43a99f82f8bd2b24eb76481d0

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.1-cp39-cp39-manylinux1_x86_64.whl
  • Upload date:
  • Size: 403.2 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.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 89eb5d150bf2c30d3775aa428e00b0a9abde7286956ec35bac1a69c42d77a202
MD5 897241f2cfa9969604987edfeb4f1c32
BLAKE2b-256 6817fb6260cad88b0064b8718d8b574a016c2d45a1c7b499c00b03292fa910d3

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.1-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 179.5 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.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 72cf6277494ab35fa855801732cff6277bca1bb8a6ccb0f6fc8c32efdfd160be
MD5 8b9afca43d23b7699a061f9806db02ec
BLAKE2b-256 07a179785720ea0c53e609040ec0fd6f6103d957fb3362f442e002f5311b0089

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 187.7 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.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a32c31880bcf23d4c3f84f4ca09a6528bd35805c96a2e9cae4a45271cfb1d3fc
MD5 d5bb387ec38d00677f081896391b2b7e
BLAKE2b-256 27f16716e1f3fe1c8e074fe43d97c8bdeaab5ea42c953593005270a66d163689

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.1-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 408.5 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.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0603b55441ae107fb294afc04909babe942475fb71279fe6d9ae25fd4690ee35
MD5 2107349103e14fed19859b801954f595
BLAKE2b-256 5663957c6903777a05c79c1e9ee8736eedf43d556a34c4f5b9c412b06c08065f

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.1-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 408.5 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.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f63fcf1549759e2834ce6ee5736d3d43ddea14bea822988c79019dbf344c2448
MD5 f82d7d8df7a324499edf00076c9b96f9
BLAKE2b-256 836ba378186d4b6734f9c526d9b724ad24474a3c328e6269006da75baf510c3e

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: msgspec-0.4.1-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 180.0 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.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for msgspec-0.4.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 465c770ce9ee526f77aa5dea672c869915b9e172605717e4b9157518c5dcfe5f
MD5 ed24fe9f30293d3d6ed50df100f8f53b
BLAKE2b-256 c43993f4868a1d31cfc34e2b52d609948caf2751ae8c7f07f5a73e1f14b98ded

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