Implementation:Alibaba MNN FlatBuffers IDL Gen Python
| Knowledge Sources | |
|---|---|
| Domains | Serialization, Code_Generation |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
Python code generator backend that produces FlatBuffers accessor classes for the Python programming language.
Description
idl_gen_python.cpp implements the Python code generation backend for flatc. It generates Python classes with accessor methods that read FlatBuffer binary data through the flatbuffers Python package. Each table produces a Python class with properties for each field, supporting both object-style access and direct buffer reads. Enums are generated as Python classes with integer constants.
Usage
Vendored dependency used internally by MNN for model serialization. Not directly imported by end users.
Code Reference
Source Location
- Repository: Alibaba_MNN
- File:
3rd_party/flatbuffers/src/idl_gen_python.cpp - Lines: 1-728
Signature
namespace flatbuffers {
bool GeneratePython(const Parser &parser,
const std::string &path,
const std::string &file_name);
}
Import
#include "flatbuffers/idl.h"
// Generator invoked internally by flatc
I/O Contract
| Input | Output |
|---|---|
| Parsed Parser object with schema definitions | *.py Python module files (one per type)
|
Usage Examples
// Invoked by flatc:
// flatc --python schema.fbs
// Internally:
flatbuffers::Parser parser;
parser.Parse(schema);
flatbuffers::GeneratePython(parser, output_path, file_name);