ランキングに戻る

jcrist/msgspec

Pythonjcristharif.com/msgspec/

A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML

msgpackserializationjsonpythonvalidationdeserializationmessagepackjson-schemaschemaserdejsonschemayaml
スター成長
スター
2.6k
フォーク
89
週間成長
Issue
146
1k2k
2023年1月2024年2月2025年3月2026年5月
成果物PyPIpip install msgspec
README

msgspec

msgspec is a fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML. It features:

  • 🚀 High performance encoders/decoders for common protocols. The JSON and MessagePack implementations regularly benchmark as the fastest options for Python.

  • 🎉 Support for a wide variety of Python types. Additional types may be supported through extensions.

  • 🔍 Zero-cost schema validation using familiar Python type annotations. In benchmarks msgspec decodes and validates JSON faster than orjson can decode it alone.

  • A speedy Struct type for representing structured data. If you already use dataclasses or attrs, structs should feel familiar. However, they're 5-60x faster for common operations.

All of this is included in a lightweight library with no required dependencies.


msgspec may be used for serialization alone, as a faster JSON or MessagePack library. For the greatest benefit though, we recommend using msgspec to handle the full serialization & validation workflow:

Define your message schemas using standard Python type annotations.

>>> import msgspec

>>> class User(msgspec.Struct):
...     """A new type describing a User"""
...     name: str
...     groups: set[str] = set()
...     email: str | None = None

Encode messages as JSON, or one of the many other supported protocols.

>>> 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 objects, 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.ValidationError: 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 ~10-80x faster than alternative libraries.

See the documentation for more information.

LICENSE

New BSD. See the License File.

関連リポジトリ
nlohmann/json

JSON for Modern C++

C++MIT Licensejsonjson-pointer
json.nlohmann.me
50.2k7.4k
MessagePack-CSharp/MessagePack-CSharp

Extremely Fast MessagePack Serializer for C#(.NET, .NET Core, Unity, Xamarin). / msgpack.org[C#]

C#Othermessagepackunity
6.7k769
focus-creative-games/luban

luban是一个强大、易用、优雅、稳定的游戏配置解决方案。luban is a powerful, easy-to-use, elegant and stable game configuration solution.

C#MIT Licenseexcelcsv
code-philosophy.com
4.5k726
msgspec/msgspec

A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML

PythonPyPIBSD 3-Clause "New" or "Revised" Licensemsgpackserialization
msgspec.dev
3.9k161
tarantool/tarantool

Get your data in RAM. Get compute close to data. Enjoy the performance.

LuaOthertarantooldatabase
tarantool.io
3.7k412
python-arq/arq

Fast job queuing and RPC in python with asyncio and redis.

PythonPyPIMIT Licenseredisconcurrent
arq-docs.helpmanual.io
3k222
vmihailenco/msgpack

msgpack.org[Go] MessagePack encoding for Golang

GoGo ModulesBSD 2-Clause "Simplified" Licensegogolang
msgpack.uptrace.dev
2.7k255
msgpack/msgpack-python

MessagePack serializer implementation for Python msgpack.org[Python]

PythonPyPIOtherpythonmsgpack
msgpack.org
2.1k253
rpclib/rpclib

rpclib is a modern C++ msgpack-RPC server and client library

C++Otherrpccpp14
rpclib.net
1.8k397
msgpack/msgpack-javascript

@msgpack/msgpack - MessagePack for JavaScript / msgpack.org[ECMA-262/JavaScript/TypeScript]

TypeScriptnpmISC Licensemsgpackjavascript-library
msgpack.org
1.6k178
laruence/yar

Light, concurrent RPC framework for PHP & C

COtheryarrpc-framework
1.4k316
3Hren/msgpack-rust

MessagePack implementation for Rust / msgpack.org[Rust]

Rustcrates.ioMIT Licenserustrmp
1.4k159