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
| Feature | pickle | JSON | pyfory |
|---|---|---|---|
| Performance | Moderate | Slow | Fast |
| Data Size | Large | Large | Compact |
| Type Support | All Python | Limited | All Python |
| Cross-Language | No | Yes | Yes (xlang mode) |
| Security | Low | High | Configurable |
Migration Tips
- Start with strict=False to ensure compatibility
- Add type registration for performance and security
- Test thoroughly before deploying
- Monitor performance improvements
Related Topics
- Configuration - Fory parameters
- Python Native Mode - Pickle replacement features
- Security - Security best practices