Blazingly fast multi-language serialization framework powered by JIT and zero-copy
npx @tessl/cli install tessl/pypi-pyfury@0.10.0PyFury is the Python implementation of Apache Fury, a blazingly fast multi-language serialization framework powered by JIT compilation and zero-copy techniques. PyFury provides high-performance serialization for Python objects with support for cross-language compatibility, reference tracking, and row format operations.
pip install pyfuryimport pyfury
from pyfury import Fury, LanguageFor row format operations:
from pyfury.format import encoder, RowDataimport pyfury
# Create Fury instance
fury = pyfury.Fury(ref_tracking=True)
# Register classes for cross-language serialization
fury.register_class(SomeClass, type_tag="example.SomeClass")
# Serialize object
obj = SomeClass()
bytes_data = fury.serialize(obj)
# Deserialize object
restored_obj = fury.deserialize(bytes_data)
# Cross-language serialization
xlang_fury = pyfury.Fury(language=pyfury.Language.XLANG, ref_tracking=True)
xlang_fury.register_class(SomeClass, type_tag="example.SomeClass")
xlang_bytes = xlang_fury.serialize(obj)
# Row format encoding for zero-copy operations
from dataclasses import dataclass
@dataclass
class DataObject:
field1: int
field2: str
row_encoder = pyfury.encoder(DataObject)
data_obj = DataObject(field1=42, field2="hello")
row_data = row_encoder.to_row(data_obj)PyFury is built around several key components:
Primary serialization operations for converting Python objects to/from binary format with optional reference tracking and circular reference support.
class Fury:
def __init__(
self,
language: Language = Language.XLANG,
ref_tracking: bool = False,
require_class_registration: bool = True,
): ...
def serialize(
self,
obj,
buffer: Buffer = None,
buffer_callback=None,
unsupported_callback=None,
) -> Union[Buffer, bytes]: ...
def deserialize(
self,
buffer: Union[Buffer, bytes],
buffers: Iterable = None,
unsupported_objects: Iterable = None,
): ...Type registration system for security and cross-language compatibility with support for custom type tags and class IDs.
class Fury:
def register_class(
self,
cls,
*,
class_id: int = None,
type_tag: str = None
): ...
def register_serializer(self, cls: type, serializer): ...
class Language(enum.Enum):
XLANG = 0
JAVA = 1
class OpaqueObject:
def __init__(self, type_id: int, data: bytes): ...Zero-copy row format encoding with PyArrow integration for efficient columnar data operations and cross-language data exchange.
@dataclass
class RowData:
def __init__(self, schema, data: bytes): ...
def encoder(cls_or_schema):
"""Create row encoder for a dataclass or Arrow schema."""
class Encoder:
def to_row(self, obj) -> RowData: ...
def from_row(self, row_data: RowData): ...
@property
def schema(self): ...
class ArrowWriter:
def write(self, obj): ...Extensible serializer system for handling custom types, built-in Python types, and cross-language compatible serialization.
class Serializer:
def __init__(self, fury, cls): ...
def write(self, buffer, value): ...
def read(self, buffer): ...
class CrossLanguageCompatibleSerializer(Serializer):
"""Base class for serializers that support cross-language serialization."""
class BufferObject:
"""Interface for objects that can provide buffer data."""
def to_buffer(self) -> bytes: ...High-performance binary buffer operations with efficient memory allocation and platform-specific optimizations.
class Buffer:
@staticmethod
def allocate(size: int) -> Buffer: ...
def write_byte(self, value: int): ...
def read_byte(self) -> int: ...
def write_int32(self, value: int): ...
def read_int32(self) -> int: ...
def write_int64(self, value: int): ...
def read_int64(self) -> int: ...
def write_bytes(self, data: bytes): ...
def read_bytes(self, length: int) -> bytes: ...class FuryError(Exception):
"""Base exception for PyFury operations."""
class ClassNotCompatibleError(FuryError):
"""Raised when class compatibility checks fail."""
class CompileError(FuryError):
"""Raised when code generation/compilation fails."""Language.XLANG for cross-language compatibility, Python mode for pure Python scenariosPyFury enables class registration by default to prevent deserialization of untrusted classes. When require_class_registration=False, PyFury can deserialize arbitrary Python objects, which may execute malicious code through __init__, __new__, __eq__, or __hash__ methods. Only disable class registration in trusted environments.