Protocol Buffer Schema Generator¶
Here's the reference information for the included Protocol Buffer schema generator classes with all their parameters, attributes and methods.
You can import these classes directly from pyrmute:
pyrmute.ProtoExporter
¶
Export Pydantic models to Protocol Buffer .proto files.
This class provides methods to export individual schemas or all schemas from a model registry to .proto files.
Initialize the Protocol Buffer exporter.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
Model registry instance.
TYPE:
|
package
|
Protobuf package name.
TYPE:
|
include_docs
|
Whether to include documentation as comments.
TYPE:
|
use_proto3
|
Use proto3 syntax (True) or proto2 (False).
TYPE:
|
Source code in src/pyrmute/protobuf_schema.py
generator
instance-attribute
¶
generator = ProtoSchemaGenerator(
package=package,
include_docs=include_docs,
use_proto3=use_proto3,
)
export_schema
¶
Export a single model version as a Protocol Buffer schema.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Model name.
TYPE:
|
version
|
Model version.
TYPE:
|
output_path
|
Optional file path to save schema (.proto file).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Protocol Buffer file as a string. |
Example
Source code in src/pyrmute/protobuf_schema.py
export_all_schemas
¶
Export all registered models as Protocol Buffer schemas.
| PARAMETER | DESCRIPTION |
|---|---|
output_dir
|
Directory to save .proto files.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, dict[str, str]]
|
Dictionary mapping model names to version to Protocol Buffer file as a |
dict[str, dict[str, str]]
|
string. |