title: Migration Guide sidebar_position: 12 id: python_migration license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
This page covers migration from pickle and JSON to pyfory.
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
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)
| 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 |