Avro Schema Generator¶
Here's the reference information for the included Avro schema generator classes with all their parameters, attributes and methods.
You can import these classes directly from pyrmute:
pyrmute.AvroSchemaGenerator
¶
Bases: SchemaGeneratorBase[AvroSchemaDocument]
Generates Apache Avro schemas from Pydantic models.
Initialize the Avro schema generator.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
Avro namespace for generated schemas (e.g., "com.mycompany.events").
TYPE:
|
include_docs
|
Whether to include field descriptions in schemas.
TYPE:
|
Source code in src/pyrmute/avro_schema.py
AVRO_SYMBOL_REGEX
class-attribute
instance-attribute
¶
generate_schema
¶
Generate an Avro schema from a Pydantic model.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Pydantic model class.
TYPE:
|
name
|
Model name.
TYPE:
|
version
|
Optional namespace version. This is often the model version.
TYPE:
|
registry_name_map
|
Optional mapping of class names to registry names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AvroSchemaDocument
|
Avro schema document. |
Source code in src/pyrmute/avro_schema.py
pyrmute.AvroExporter
¶
Export Pydantic models to Avro schema files.
This class provides methods to export individual schemas or all schemas from a model _registry to .avsc (Avro Schema) files.
Initialize the Avro exporter.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
Model registry instance.
TYPE:
|
namespace
|
Avro namespace for schemas.
TYPE:
|
include_docs
|
Whether to include documentation.
TYPE:
|
Source code in src/pyrmute/avro_schema.py
generator
instance-attribute
¶
generator = AvroSchemaGenerator(
namespace=namespace, include_docs=include_docs
)
export_schema
¶
Export a single model version as an Avro schema.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Model name.
TYPE:
|
version
|
Model version.
TYPE:
|
output_path
|
Optional file path to save schema.
TYPE:
|
versioned_namespace
|
Include model version in namespace. Default False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AvroRecordSchema
|
Avro record schema. |
Example
Source code in src/pyrmute/avro_schema.py
export_all_schemas
¶
Export all registered models as Avro schemas.
| PARAMETER | DESCRIPTION |
|---|---|
output_dir
|
Directory to save schema files.
TYPE:
|
indent
|
JSON indentation level.
TYPE:
|
versioned_namespace
|
Include model version in namespace. Default False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, dict[str, AvroRecordSchema]]
|
Dictionary mapping model names to version to schema. |