title: Schema Evolution sidebar_position: 6 id: python_schema_evolution 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
Apache Fory™ supports schema evolution in Compatible mode, allowing fields to be added/removed while maintaining compatibility.
import pyfory f = pyfory.Fory(xlang=True, compatible=True)
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 = "unknown@example.com" # New field with default # Can still deserialize old data user = f.loads(data) print(user.email) # "unknown@example.com"