High-performance cross-language serialization framework. Fory provides blazingly-fast serialization for Python objects with support for both Python native mode and xlang mode. Xlang mode handles registered schema objects and cross-language reference metadata; Python native mode han
| 80 | |
| 81 | |
| 82 | class Fory: |
| 83 | """ |
| 84 | High-performance cross-language serialization framework. |
| 85 | |
| 86 | Fory provides blazingly-fast serialization for Python objects with support for |
| 87 | both Python native mode and xlang mode. Xlang mode handles registered schema |
| 88 | objects and cross-language reference metadata; Python native mode handles the |
| 89 | broader Python object graph surface, including circular Python objects. |
| 90 | |
| 91 | In Python native mode (xlang=False), Fory can serialize all Python objects |
| 92 | including dataclasses, classes with custom serialization methods, and local |
| 93 | functions/classes, making it a drop-in replacement for pickle. |
| 94 | |
| 95 | In xlang mode, the default, Fory serializes objects in a format that can be |
| 96 | deserialized by other Fory-supported languages (Java, Go, Rust, C++, etc.). |
| 97 | |
| 98 | Examples: |
| 99 | >>> import pyfory |
| 100 | >>> from dataclasses import dataclass |
| 101 | >>> |
| 102 | >>> @dataclass |
| 103 | >>> class Person: |
| 104 | ... name: str |
| 105 | ... age: pyfory.Int32 |
| 106 | >>> |
| 107 | >>> fory = pyfory.Fory(xlang=True) |
| 108 | >>> fory.register(Person, name="example.Person") |
| 109 | >>> data = fory.serialize(Person("Alice", 30)) |
| 110 | >>> person = fory.deserialize(data) |
| 111 | |
| 112 | See Also: |
| 113 | ThreadSafeFory: Thread-safe wrapper for concurrent usage |
| 114 | """ |
| 115 | |
| 116 | __slots__ = ( |
| 117 | "config", |
| 118 | "xlang", |
| 119 | "compatible", |
| 120 | "track_ref", |
| 121 | "type_resolver", |
| 122 | "write_context", |
| 123 | "read_context", |
| 124 | "strict", |
| 125 | "buffer", |
| 126 | "max_depth", |
| 127 | "field_nullable", |
| 128 | "policy", |
| 129 | ) |
| 130 | |
| 131 | def __init__( |
| 132 | self, |
| 133 | xlang: bool = True, |
| 134 | ref: bool = False, |
| 135 | strict: bool = True, |
| 136 | compatible: Optional[bool] = None, |
| 137 | max_depth: int = 50, |
| 138 | max_type_fields: int = 512, |
| 139 | max_type_meta_bytes: int = 4096, |
no outgoing calls