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

Skip to main content
Version: 0.14

Schema Evolution

Apache Fory™ supports schema evolution in Compatible mode, allowing fields to be added/removed while maintaining compatibility.

Enable Compatible Mode

import pyfory

f = pyfory.Fory(xlang=True, compatible=True)

Schema Evolution Example

import pyfory
from dataclasses import dataclass

# Version 1: Original class
@dataclass
class User:
name: str
age: int

f = pyfory.Fory(xlang=True, compatible=True)
f.register(User, typename="User")
data = f.dumps(User("Alice", 30))

# Version 2: Add new field (backward compatible)
@dataclass
class User:
name: str
age: int
email: str = "[email protected]" # New field with default

# Can still deserialize old data
user = f.loads(data)
print(user.email) # "[email protected]"

Supported Changes

  • Add new fields: With default values
  • Remove fields: Old data with extra fields will be skipped
  • Reorder fields: Fields are matched by name, not position

Best Practices

  1. Always provide default values for new fields
  2. Use typename for cross-language compatibility
  3. Test schema changes before deploying
  4. Document schema versions for your team