Skip to main content

Fast and friendly msgpack (de)serialization, with type validation

Project description

github pypi

msgspec is a fast and friendly implementation of the MessagePack (msgpack) protocol for Python 3.8+. In addition to serialization/deserialization, it supports message validation using schemas defined via Python’s type annotations.

from typing import Optional, List
import msgspec

# Define a schema for a `User` type
class User(msgspec.Struct):
    name: str
    groups: List[str] = []
    email: Optional[str] = None

# Create a `User` object
alice = User("alice", groups=["admin", "engineering"])

# Serialize `alice` to `bytes` using the MessagePack protocol
serialized_data = msgspec.encode(alice)

# Deserialize and validate the message as a User type
user = msgspec.decode(serialized_data, type=User)

assert user == alice

msgspec is designed to be as performant as possible, while retaining some of the nicities of validation libraries like pydantic. For supported types, serializing a message with msgspec can be ~2-4x 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.3.2.tar.gz (50.2 kB view hashes)

Uploaded Source

Built Distributions

msgspec-0.3.2-cp39-cp39-win_amd64.whl (71.7 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

msgspec-0.3.2-cp39-cp39-manylinux2010_x86_64.whl (192.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

msgspec-0.3.2-cp39-cp39-manylinux1_x86_64.whl (192.8 kB view hashes)

Uploaded CPython 3.9

msgspec-0.3.2-cp39-cp39-macosx_10_9_x86_64.whl (66.1 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

msgspec-0.3.2-cp38-cp38-win_amd64.whl (71.5 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

msgspec-0.3.2-cp38-cp38-manylinux2010_x86_64.whl (193.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

msgspec-0.3.2-cp38-cp38-manylinux1_x86_64.whl (193.1 kB view hashes)

Uploaded CPython 3.8

msgspec-0.3.2-cp38-cp38-macosx_10_9_x86_64.whl (66.1 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

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