Thanks to visit codestin.com
Credit goes to fory.apache.org

Skip to main content
Version: 0.14

Migration Guide

This page covers migration from pickle and JSON to pyfory.

From Pickle

Replace pickle with Fory for better performance while keeping the same API:

# Before (pickle)
import pickle
data = pickle.dumps(obj)
result = pickle.loads(data)

# After (Fory - drop-in replacement with better performance)
import pyfory
f = pyfory.Fory(xlang=False, ref=True, strict=False)
data = f.dumps(obj) # Faster and more compact
result = f.loads(data) # Faster deserialization

# Benefits:
# - 2-10x faster serialization
# - 2-5x faster deserialization
# - Up to 3x smaller data size
# - Same API, better performance

From JSON

Unlike JSON, Fory supports arbitrary Python types including functions:

# Before (JSON - limited types)
import json
data = json.dumps({"name": "Alice", "age": 30})
result = json.loads(data)

# After (Fory - all Python types)
import pyfory
f = pyfory.Fory()
data = f.dumps({"name": "Alice", "age": 30, "func": lambda x: x})
result = f.loads(data)

Key Differences

FeaturepickleJSONpyfory
PerformanceModerateSlowFast
Data SizeLargeLargeCompact
Type SupportAll PythonLimitedAll Python
Cross-LanguageNoYesYes (xlang mode)
SecurityLowHighConfigurable

Migration Tips

  1. Start with strict=False to ensure compatibility
  2. Add type registration for performance and security
  3. Test thoroughly before deploying
  4. Monitor performance improvements