schema_salad.avro.schema

Contains the Schema classes.

A schema may be one of:

A record, mapping field names to field value data; An enum, containing one of a small set of symbols; An array of values, all of the same schema; A map of values, all of the same schema; A union of other schemas; A unicode string; A 32-bit signed int; A 64-bit signed long; A 32-bit floating-point float; A 64-bit floating-point double; A boolean; or Null.

Attributes

PRIMITIVE_TYPES

NAMED_TYPES

VALID_TYPES

SCHEMA_RESERVED_PROPS

JsonDataType

AtomicPropType

PropType

PropsType

FIELD_RESERVED_PROPS

VALID_FIELD_SORT_ORDERS

Exceptions

AvroException

Indicates error with the provided schema definition.

SchemaParseException

Indicates error with the provided schema definition.

Classes

Schema

Base class for all Schema classes.

Name

Class to describe Avro name.

Names

Track name set and default namespace during parsing.

NamedSchema

Named Schemas specified in NAMED_TYPES.

Field

PrimitiveSchema

Valid primitive types are in PRIMITIVE_TYPES.

EnumSchema

Named Schemas specified in NAMED_TYPES.

ArraySchema

Avro array schema class.

MapSchema

Avro map schema class.

NamedMapSchema

Avro named map schema class.

UnionSchema

Avro union schema class.

NamedUnionSchema

Avro named union schema class.

RecordSchema

Named Schemas specified in NAMED_TYPES.

Functions

get_other_props(all_props, reserved_props)

Retrieve the non-reserved properties from a dictionary of properties.

make_avsc_object(json_data[, names])

Build Avro Schema from data parsed out of JSON string.

is_subtype(types, existing, new)

Check if a new type specification is compatible with an existing type spec.

Module Contents

schema_salad.avro.schema.PRIMITIVE_TYPES = ('null', 'boolean', 'string', 'int', 'long', 'float', 'double')
schema_salad.avro.schema.NAMED_TYPES = ('enum', 'record')
schema_salad.avro.schema.VALID_TYPES
schema_salad.avro.schema.SCHEMA_RESERVED_PROPS = ('type', 'name', 'namespace', 'fields', 'items', 'names', 'symbols', 'values', 'doc')
schema_salad.avro.schema.JsonDataType
schema_salad.avro.schema.AtomicPropType
schema_salad.avro.schema.PropType
schema_salad.avro.schema.PropsType
schema_salad.avro.schema.FIELD_RESERVED_PROPS = ('default', 'name', 'doc', 'order', 'type')
schema_salad.avro.schema.VALID_FIELD_SORT_ORDERS = ('ascending', 'descending', 'ignore')
exception schema_salad.avro.schema.AvroException(msg, sl=None, children=None, bullet_for_children='', detailed_message=None)

Bases: schema_salad.exceptions.SchemaException

Inheritance diagram of schema_salad.avro.schema.AvroException

Indicates error with the provided schema definition.

Parameters:
exception schema_salad.avro.schema.SchemaParseException(msg, sl=None, children=None, bullet_for_children='', detailed_message=None)

Bases: AvroException

Inheritance diagram of schema_salad.avro.schema.SchemaParseException

Indicates error with the provided schema definition.

Parameters:
class schema_salad.avro.schema.Schema(atype, other_props=None)

Base class for all Schema classes.

Parameters:
  • atype (str)

  • other_props (Optional[PropsType])

type
property props: PropsType
Return type:

PropsType

get_prop(key)
Parameters:

key (str)

Return type:

Optional[PropType]

set_prop(key, value)
Parameters:
  • key (str)

  • value (Optional[PropType])

Return type:

None

class schema_salad.avro.schema.Name(name_attr=None, space_attr=None, default_space=None)

Class to describe Avro name.

Parameters:
  • name_attr (Optional[str])

  • space_attr (Optional[str])

  • default_space (Optional[str])

property fullname: str | None
Return type:

Optional[str]

get_space()

Back out a namespace from full name.

Return type:

Optional[str]

class schema_salad.avro.schema.Names(default_namespace=None)

Track name set and default namespace during parsing.

Parameters:

default_namespace (Optional[str])

names: dict[str, NamedSchema]
default_namespace
has_name(name_attr, space_attr)
Parameters:
  • name_attr (str)

  • space_attr (Optional[str])

Return type:

bool

get_name(name_attr, space_attr)

Fetch the stored schema for the given namespace.

Parameters:
  • name_attr (str)

  • space_attr (Optional[str])

Return type:

Optional[NamedSchema]

add_name(name_attr, space_attr, new_schema)

Add a new schema object to the name set.

Parameters:
  • name_attr (str) – name value read in schema

  • space_attr (Optional[str]) – namespace value read in schema.

  • new_schema (NamedSchema)

Returns:

the Name that was just added.

Return type:

Name

class schema_salad.avro.schema.NamedSchema(atype, name, namespace=None, names=None, other_props=None)

Bases: Schema

Inheritance diagram of schema_salad.avro.schema.NamedSchema

Named Schemas specified in NAMED_TYPES.

Parameters:
  • atype (str)

  • name (str)

  • namespace (Optional[str])

  • names (Optional[Names])

  • other_props (Optional[PropsType])

property name: str
Return type:

str

class schema_salad.avro.schema.Field(atype, name, has_default, default=None, order=None, names=None, doc=None, other_props=None)
Parameters:
  • atype (JsonDataType)

  • name (str)

  • has_default (bool)

  • default (Optional[Any])

  • order (Optional[str])

  • names (Optional[Names])

  • doc (Optional[Union[str, list[str]]])

  • other_props (Optional[PropsType])

type
name
property default: Any | None
Return type:

Optional[Any]

get_prop(key)
Parameters:

key (str)

Return type:

Optional[PropType]

set_prop(key, value)
Parameters:
  • key (str)

  • value (Optional[PropType])

Return type:

None

class schema_salad.avro.schema.PrimitiveSchema(atype, other_props=None)

Bases: Schema

Inheritance diagram of schema_salad.avro.schema.PrimitiveSchema

Valid primitive types are in PRIMITIVE_TYPES.

Parameters:
  • atype (str)

  • other_props (Optional[PropsType])

fullname
class schema_salad.avro.schema.EnumSchema(name, namespace, symbols, names=None, doc=None, other_props=None)

Bases: NamedSchema

Inheritance diagram of schema_salad.avro.schema.EnumSchema

Named Schemas specified in NAMED_TYPES.

Parameters:
  • name (str)

  • namespace (Optional[str])

  • symbols (list[str])

  • names (Optional[Names])

  • doc (Optional[Union[str, list[str]]])

  • other_props (Optional[PropsType])

property symbols: list[str]

Retrieve the list of symbols.

Return type:

list[str]

class schema_salad.avro.schema.ArraySchema(items, names, other_props=None)

Bases: Schema

Inheritance diagram of schema_salad.avro.schema.ArraySchema

Avro array schema class.

Parameters:
  • items (JsonDataType)

  • names (Names)

  • other_props (Optional[PropsType])

property items: Schema

Avro schema describing the array items’ type.

Return type:

Schema

class schema_salad.avro.schema.MapSchema(values, names, other_props=None)

Bases: Schema

Inheritance diagram of schema_salad.avro.schema.MapSchema

Avro map schema class.

Parameters:
  • values (JsonDataType)

  • names (Names)

  • other_props (Optional[PropsType])

property values: Schema

Avro schema describing the map values’ type.

Return type:

Schema

class schema_salad.avro.schema.NamedMapSchema(values, names, name, namespace=None, doc=None, other_props=None)

Bases: NamedSchema

Inheritance diagram of schema_salad.avro.schema.NamedMapSchema

Avro named map schema class.

Parameters:
  • values (JsonDataType)

  • names (Names)

  • name (str)

  • namespace (Optional[str])

  • doc (Optional[Union[str, list[str]]])

  • other_props (Optional[PropsType])

property values: Schema

Avro schema describing the map values’ type.

Return type:

Schema

class schema_salad.avro.schema.UnionSchema(schemas, names)

Bases: Schema

Inheritance diagram of schema_salad.avro.schema.UnionSchema

Avro union schema class.

Parameters:
property schemas: list[Schema]

Avro schemas composing the Union type.

Return type:

list[Schema]

class schema_salad.avro.schema.NamedUnionSchema(schemas, names, name, namespace=None, doc=None)

Bases: NamedSchema

Inheritance diagram of schema_salad.avro.schema.NamedUnionSchema

Avro named union schema class.

Parameters:
property schemas: list[Schema]

Retrieve the list of schemas.

Return type:

list[Schema]

class schema_salad.avro.schema.RecordSchema(name, namespace, fields, names, schema_type='record', doc=None, other_props=None)

Bases: NamedSchema

Inheritance diagram of schema_salad.avro.schema.RecordSchema

Named Schemas specified in NAMED_TYPES.

Parameters:
  • name (str)

  • namespace (Optional[str])

  • fields (list[PropsType])

  • names (Names)

  • schema_type (str)

  • doc (Optional[Union[str, list[str]]])

  • other_props (Optional[PropsType])

static make_field_objects(field_data, names)

We’re going to need to make message parameters too.

Parameters:
Return type:

list[Field]

property fields: list[Field]

Retrieve the fields list.

Return type:

list[Field]

schema_salad.avro.schema.get_other_props(all_props, reserved_props)

Retrieve the non-reserved properties from a dictionary of properties.

Parameters:
  • reserved_props (tuple[str, Ellipsis]) – The set of reserved properties to exclude

  • all_props (PropsType)

Return type:

Optional[PropsType]

schema_salad.avro.schema.make_avsc_object(json_data, names=None)

Build Avro Schema from data parsed out of JSON string.

Parameters:
  • names (Optional[Names]) – A Name object (tracks seen names and default space)

  • json_data (JsonDataType)

Return type:

Schema

schema_salad.avro.schema.is_subtype(types, existing, new)

Check if a new type specification is compatible with an existing type spec.

Parameters:
  • types (dict[str, Any])

  • existing (PropType)

  • new (PropType)

Return type:

bool