or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-functions.mdexceptions.mdindex.mdstreaming.mdtypes.md
tile.json

tessl/pypi-msgpack

MessagePack serializer for efficient binary data exchange among multiple languages

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/msgpack@1.1.x

To install, run

npx @tessl/cli install tessl/pypi-msgpack@1.1.0

index.mddocs/

MessagePack

MessagePack is an efficient binary serialization format that enables data exchange among multiple languages like JSON but is faster and smaller. This Python implementation provides CPython bindings for high performance and a pure Python fallback for PyPy compatibility.

Package Information

  • Package Name: msgpack
  • Language: Python
  • Installation: pip install msgpack

Core Imports

import msgpack

Common usage pattern:

from msgpack import packb, unpackb

For streaming applications:

from msgpack import Packer, Unpacker

Basic Usage

import msgpack

# Pack Python objects to binary data
data = {'name': 'Alice', 'age': 30, 'scores': [95, 87, 92]}
packed = msgpack.packb(data)

# Unpack binary data back to Python objects
unpacked = msgpack.unpackb(packed)
print(unpacked)  # {'name': 'Alice', 'age': 30, 'scores': [95, 87, 92]}

# File operations
with open('data.msgpack', 'wb') as f:
    msgpack.pack(data, f)

with open('data.msgpack', 'rb') as f:
    loaded_data = msgpack.unpack(f)

Architecture

MessagePack Python provides two implementation paths:

  • C Extension: High-performance implementation using Cython (msgpack._cmsgpack)
  • Pure Python: Fallback implementation for PyPy compatibility (msgpack.fallback)

The library automatically selects the best available implementation unless overridden via the MSGPACK_PUREPYTHON environment variable.

Capabilities

High-Level Functions

Core convenience functions for one-shot packing and unpacking operations, providing simple interfaces for the most common serialization tasks.

def packb(o, **kwargs): ...
def unpackb(packed, **kwargs): ...
def pack(o, stream, **kwargs): ...  
def unpack(stream, **kwargs): ...

Core Functions

Streaming Classes

Advanced classes for efficient streaming serialization and deserialization, enabling processing of large datasets and continuous data streams.

class Packer:
    def __init__(self, **kwargs): ...
    def pack(self, obj): ...

class Unpacker:
    def __init__(self, file_like=None, **kwargs): ...
    def feed(self, data): ...
    def unpack(self): ...

Streaming

Custom Types

Specialized types for handling extension data and timestamps, enabling custom serialization of complex data structures.

class ExtType:
    def __init__(self, code: int, data: bytes): ...

class Timestamp:
    def __init__(self, seconds: int, nanoseconds: int = 0): ...

Types

Exception Handling

Comprehensive exception hierarchy for robust error handling during serialization and deserialization operations.

class UnpackException(Exception): ...
class FormatError(ValueError, UnpackException): ...
class ExtraData(UnpackValueError): ...

Exceptions