title: Overview sidebar_position: 1 id: index 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
Fory IDL is a schema definition language for Apache Fory that enables type-safe cross-language serialization. Define your data structures once and generate native data structure code for Java, Python, Go, Rust, C++, C#, Swift, JavaScript, and Dart.
Fory IDL provides a simple, intuitive syntax for defining cross-language data structures:
package example; enum Status { PENDING = 0; ACTIVE = 1; COMPLETED = 2; } message User { string name = 1; int32 age = 2; optional string email = 3; list<string> tags = 4; } message Item { string sku = 1; int32 quantity = 2; } message Order { ref User customer = 1; list<Item> items = 2; Status status = 3; map<string, int32> metadata = 4; } message Dog [id=104] { string name = 1; int32 bark_volume = 2; } message Cat [id=105] { string name = 1; int32 lives = 2; } union Animal [id=106] { Dog dog = 1; Cat cat = 2; }
Define your data model once in Fory IDL and generate consistent, type-safe code across all languages. This ensures:
Unlike generic IDLs, Fory IDL is designed specifically for Fory serialization:
refoptional modifier for nullable typesGenerated code uses native language constructs:
@ForyField annotations#[derive(ForyObject)]FORY_STRUCT macros[ForyObject] and registration helpers@ForyObject models with @ForyField metadata and registration helpers@ForyStruct classes with @ForyField annotations and registration helperspip install fory-compiler
Or install from source:
cd compiler pip install -e .
Create example.fdl:
package example; message Person { string name = 1; int32 age = 2; optional string email = 3; }
# Generate for all languages foryc example.fdl --output ./generated # Generate for specific languages foryc example.fdl --lang java,python,csharp,javascript,swift,dart --output ./generated
Java:
Person person = new Person(); person.setName("Alice"); person.setAge(30); byte[] data = person.toBytes();
Python:
import pyfory from example import Person person = Person(name="Alice", age=30) data = bytes(person) # or `person.to_bytes()`
| Document | Description |
|---|---|
| Fory IDL Syntax | Complete language syntax and grammar |
| Type System | Primitive types, collections, and type rules |
| Compiler Guide | CLI options and build integration |
| Generated Code | Output format for each target language |
| Protocol Buffers IDL Support | Comparison with protobuf and migration guide |
| FlatBuffers IDL Support | FlatBuffers mapping rules and codegen differences |
optional: Field can be null/Noneref: Enable reference tracking for shared/circular referenceslist: Field is a list/array (alias: repeated)message Example { optional string nullable = 1; ref Node parent = 2; list<int32> numbers = 3; }
Fory IDL types map to native types in each language:
| Fory IDL Type | Java | Python | Go | Rust | C++ | C# | JavaScript | Swift | Dart |
|---|---|---|---|---|---|---|---|---|---|
int32 | int | pyfory.int32 | int32 | i32 | int32_t | int | number | Int32 | Int32 |
string | String | str | string | String | std::string | string | string | String | String |
bool | boolean | bool | bool | bool | bool | bool | boolean | Bool | bool |
See Type System for complete mappings.
optional explicitly: Make nullability clear in the schemaref for shared objects: Enable reference tracking when objects are sharedSee the examples directory for complete working examples.