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

Uploaded Source

Built Distributions

msgspec-0.6.0-cp310-cp310-win_amd64.whl (210.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

msgspec-0.6.0-cp310-cp310-musllinux_1_1_x86_64.whl (453.5 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

msgspec-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (455.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

msgspec-0.6.0-cp310-cp310-macosx_10_9_x86_64.whl (207.4 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

msgspec-0.6.0-cp39-cp39-win_amd64.whl (210.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

msgspec-0.6.0-cp39-cp39-musllinux_1_1_x86_64.whl (452.5 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

msgspec-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (454.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

msgspec-0.6.0-cp39-cp39-macosx_10_9_x86_64.whl (207.3 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

msgspec-0.6.0-cp38-cp38-win_amd64.whl (210.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

msgspec-0.6.0-cp38-cp38-musllinux_1_1_x86_64.whl (458.4 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

msgspec-0.6.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (459.4 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

msgspec-0.6.0-cp38-cp38-macosx_10_9_x86_64.whl (207.2 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: msgspec-0.6.0.tar.gz
  • Upload date:
  • Size: 128.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for msgspec-0.6.0.tar.gz
Algorithm Hash digest
SHA256 27c9615be6a32898d95ba0c7b17251ee4c2d9f5fe51b61b4e1086cf6e017bec1
MD5 7eb465e6c84beccca62eabee45949b03
BLAKE2b-256 4bd9b6f37e2662f7abba3b40d763292381978a251ebb5e3fe1fdb98f4b22219a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.6.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 210.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for msgspec-0.6.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 141240ba69556eba7adc085dd653178c5679af80979695434174b9b7df46ad10
MD5 20c12b05e8f4d726d6828bac426beaad
BLAKE2b-256 93fde4ceb06dd186614680a7e9ec8223ed65f3f7a4853201991c32bfcd8bd815

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for msgspec-0.6.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d86573b780e43c0d05f65bcffd683ee1c43b79cace3d0528f73f7c808800fabb
MD5 32e03a894084999229db1303268281fd
BLAKE2b-256 f0f0069e0ee388cb63d9463ae98e767426f82ebc910a85254f791d27157eb84f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for msgspec-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 388cd4036b79cd718a635999f9482f8a95b7ec8481ece848079b55f84aa61395
MD5 e7cd6f1a3904ce896fb0652fdcafa0dc
BLAKE2b-256 b686f0dfcb6913dcee2c98bef570408ce81b712611cf40e01aa6e5cb3c8a7be9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for msgspec-0.6.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b12e831cc54b26d19b8f22935c85b475bc8d1fc03f7333da54c9f9ced950b6d8
MD5 a890d721417eb576ba29c1a2868156aa
BLAKE2b-256 1ef94752a2ac468dc59b54e33a5ab54144af76c090f46824501a1b7ca834cdcc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.6.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 210.0 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for msgspec-0.6.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ea0f848255520cc3695ba9c174645c64233a6e0195240f00399d4c0ea5888b34
MD5 d78035c3f1d7ee6745c997d4ca0405fa
BLAKE2b-256 32350957143e85ccf766214e8ca78097c88396d8599cdfac0b54905a653775ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for msgspec-0.6.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3b8ff0237bb81b48ed680749043a969fa56ff06c13120944d2f4432fb3af4888
MD5 f5899959627298ac0ae291f2469118a0
BLAKE2b-256 24d1777fa7e46e49584faec423bb9845f525405be7ed88568364b9ea244c8464

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for msgspec-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5ef7ef54494183ddef8ac4e21eb3fc6d7fbcdc7b56d6a19414e51a672bdaa3e6
MD5 d2a7e959a04746d794cfc62d41f52641
BLAKE2b-256 ccbc28734764bcdc253d5258b3a0f668d49a8a1a93adb01ea6d7e1b31bb72e2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for msgspec-0.6.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 559f749bbbf691c708bed998be472eea994cad1e846bbc9a68f19af8d7179041
MD5 a1bf6c87da0957cee68555dbfe5a31cc
BLAKE2b-256 d4e41e0630d9f25c183dc84735251eb302ed0b3e9a6537574c4928cf370f3297

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspec-0.6.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 210.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for msgspec-0.6.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 7b2fbbb71ae7420dd3b81c217434fe89065bdcb14e8c885b3e1d2bf401b0b7a0
MD5 39fda978cb52327778f9f48f2a4bf068
BLAKE2b-256 f3a08e7ec836357b47807ed9fb579af25d0365e941344f7faed0093fd34a2874

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for msgspec-0.6.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 25e8359c7725826deb8fad3340fc206f017fd041245d0633fb257fd47fc99199
MD5 8b92b71a87ce447c9c357899dc6a4ba2
BLAKE2b-256 a05999586438c2cca2ee5de0525c8c224459d8c7d0282a8b955e4031a75506b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for msgspec-0.6.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a3d8dcbc3ad69f741637fb6c69b09d7c4b44a95ca388da91220446525988c5da
MD5 4b59a35d906e50e90c2ea2fbdf7bd9ed
BLAKE2b-256 235640f15c6f18424cda4982e6ab346111210921d177ef1f024e56746d3e5730

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for msgspec-0.6.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 411e594c1388cc978d6bba5f636d0f7f6c18b8813f0c9199c95bd17db3b4d63c
MD5 a5b0d3b9ed452e56c085fd95cbe9dc58
BLAKE2b-256 206f7c228798cb15ae20f3cfcffd1ca9a8a98629f5d1a4098dbb90563fbb708c

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