API Reference
All members of cavro are defined in the top-level module.
Currently, the docs are a little funky, because cython doesn't expose Signtaure information that easily, and pdoc
isn't geared up to handle it. This may change in the future.
Main Interface Classes
class Schema
The main interface for cavro
.
This class represents an avro schema, and is able to encode and decode values appropriately.
Arguments:
source
: The source of the schema. This can either be a string that holds the JSON-encoded schema definition, or a python object that represents the schema (e.g. the result ofjson.loads
).options
: An instance ofOptions
that controls how the schema is interpreted. Defaults toDEFAULT_OPTIONS
.named_types
: An optional dictionary that will be updated to contain any named types that are encountered while parsing the schema.parse_json
: IfFalse
then thesource
argument will never be parsed as json, even if it's a string value. Defaults toTrue
.**extra_options
: Any extra options that should be applied to the schema. These will override any options that are set in theoptions
argument. Key-values here must match the attributes ofcavro.Options
.
Members:
init Schema(self, /, *args, **kwargs)
method fingerprint(self, method='rabin', **kwargs) → Union[bytes, _hashlib.HASH]
Return the deterministic fingerprint of the schema, using the given hash method.
**kwargs
are passed to the relevant hashlib.new()
call.
Return type is controlled by the fingerprint_returns_digest
option.
method can_encode(self, value: object) → bool
Check if value
can be encoded using this schema
method binary_encode(self, value: object) → bytes
Encode value
using this schema and return the avro bytes representing it.
method binary_decode(self, value: bytes) → object
Decode value
using this schema and return the decoded value.
method json_encode(self, value, serialize=True, **kwargs)
Encode value
using this schema and return the avro json representing it.
method json_decode(self, value: Union[str, object], deserialize: bool = True, **kwargs)
Decode value
in JSON form using this schema and return the decoded value.
If deserialize
is True, then value must be a str
containing the serialized JSON value.
If deserialize
is False, then value must be a python object representing the JSON value.
attr canonical_form
Returns the canonical form of the schema as a string
attr schema
Return an object representing the schema definition.
Note: This will not always be identical to the source
used to construct this schema object, as it is reconstructed from the types on-demand.
attr schema_str
Schema.schema
, but json encoded
attr named_types
attr source
attr options
attr type
attr logical_types
method find_type(self, namespace, name, _raise=True)
Given a namespace and name (namespace may be None), find and return the AvroType
instance matching this name.
method binary_read(self, reader: cavro._Reader)
Read a value from reader
using this schema and return the decoded value.
reader
may be a MemoryReader
or FileReader
instance.
method binary_write(self, writer: cavro._Writer, value: object)
Write value
to writer
using this schema.
writer
may be a MemoryWriter
or FileWriter
instance.
method reader_for_writer(self, writer_schema: cavro.Schema)
Return a schema that is the result of promoting this schema to the writer schema.
The returned schema may only be used for reading, and should return values that match the reader schema.
class Options
Runtime configuration options for controlling the behaviour
of a schema.
Instances of Options
are immutable, create a modified copy of options, use the replace
and with_*
methods.
Attributes:
fingerprint_returns_digest
IfTrue
, theSchema.fingerprint
method returns a hashlib hash object, rather than the digest bytescanonical_form_repeat_fixed
Some libraries repeat enum type definitions with the same name/size in canonical form. Setting this flag to True replicates thatcanonical_form_repeat_enum
Some libraries repeat enum type definitions with the same name/symbols in canonical form. Setting this flag to True replicates thatrecord_can_encode_dict
IfTrue
, dicts can be encoded as records (provided they have the correct fields). If false, then an instance of the relevant record type must be used.record_values_type_hint
IfTrue
, then dicts encoded using a record schema can have an optional key-type
(note the leading '-') with a value that is the name of the record, ensuring the correct record schema is chosen.record_decodes_to_dict
IfTrue
, then records are decoded to a dict, rather than a record class instancerecord_allow_extra_fields
IfTrue
, then any fields in a dict that are not in the record schema are ignored. IfFalse
, then an error is raised.record_fields_must_be_unique
IfTrue
, then all fields within a record must have a unique namerecord_encode_use_defaults
IfTrue
, then when encoding a dict as a record, any fields that are not present in the dict are encoded using their default value from the schema. IfFalse
, then an error is raised for any missing keysmissing_values_can_be_null
IfTrue
, then missing values may be encoded asnull
where this is valid in the schema. (i.e.['null', 'string']
)missing_values_can_be_empty_container
IfTrue
, then missing values may be encoded as an empty container (list, dict) where this is valid in the schema.allow_tuple_notation
IfTrue
, then values can be encoded by passing a 2-tuple of (‹type›, ‹value›) where ‹type› is the name of the type to encode as, and ‹value› is the value to encode.union_decodes_to
Controls how union values are decoded. SeeUnionDecodeOption
for details. The default,UnionDecodeOption.RAW_VALUES
returns the value from the matching union unmodified.union_json_encodes_type_name
IfTrue
(default), then when JSON encoding a value in a union, the type name is included in the output as per spec. IfFalse
, then the JSON-encoded value of the matching union type is output directly.allow_primitive_name_collision
IfTrue
, then named types can have the same name as one of the primitive types (e.g.int
,float
,str
etc..)allow_primitive_names_in_namespaces
IfTrue
, then namespace parts can have the same name as one of the primitive types (e.g.int
,float
,str
etc..)named_type_names_must_be_unique
IfTrue
, then all named types must have a unique name within the schemaenum_symbols_must_be_unique
IfTrue
, then all symbols within an enum must be uniqueenforce_enum_symbol_name_rules
IfTrue
, then enum symbol values are checked to ensure they match the rules for valid symbolsenforce_type_name_rules
IfTrue
, then type names are checked to ensure they match the rules for valid namesenforce_namespace_name_rules
IfTrue
, then namespace names are checked to ensure they match the rules for valid namesascii_name_rules
IfTrue
, then name checking (names/symbols) is done using the strict ASCII rules in the spec. IfFalse
, then equivalent unicode rules are used.allow_false_values_for_null
IfTrue
, then a null type will accept any value for whichbool(value)
isFalse
, otherwise an error is raised for any non-None
value.allow_empty_unions
IfTrue
, then unions can be empty (i.e.[]
), otherwise an error is raised.allow_nested_unions
IfTrue
, then unions can contain other unions, otherwise an error is raised.allow_duplicate_union_types
IfTrue
, then unions can contain multiple types that are forbidden from being in the same union by the spec.allow_union_default_any_member
IfTrue
, then the default value for a union can match the schema of any member of the union, otherwise the default value must match the first member of the union.allow_aliases_to_be_string
IfTrue
, then aliases can be specified as a string or a list IfFalse
, then aliases must be specified as a listcoerce_values_to_int
IfTrue
, then values encoded inint
orlong
schemas will be coerced toint
where possiblecoerce_values_to_float
IfTrue
, then values encoded infloat
ordouble
schemas will be coerced tofloat
where possiblecoerce_int_to_float
IfTrue
, thenfloat
anddouble
types will acceptint
values, and encode them as the closest floating-point valuecoerce_values_to_boolean
IfTrue
, then values encoded inboolean
schemas will be coerced tobool
where possiblecoerce_values_to_str
IfTrue
, then values encoded instring
schemas will be coerced tostr
where possiblebytes_codec
If notNone
, then values passed to bytes schemas will be encoded using the specified codecfixed_codec
If notNone
, then values passed to fixed schemas will be encoded using the specified codecnull_pad_fixed
IfTrue
, then values encoded infixed
schemas will be zero-padded to the specified sizetruncate_fixed
IfTrue
, then values encoded infixed
schemas will be truncated to the specified size (extra bytes will be dropped on encoding)clamp_int_overflow
IfTrue
, then values encoded inint
schemas will be clamped to the min/max values for the specified sizeclamp_float_overflow
IfTrue
, then values encoded in thefloat
schema will be clamped to the min/max values 32-bit floats. (Note, this also replaces INF/NaN values with the closest representable value unlessfloat_out_of_range_inf
is `True)float_out_of_range_inf
IfTrue
, then values encoded in thefloat
schema that are out of range will be encoded as INF/NaN, otherwise an error is raised.bytes_default_value_utf8
IfTrue
, then the default value for a bytes schema is encoded as UTF-8, otherwise it is encoded as latin1, this should probably never be used except for library compatibility reasonsstring_types_default_unchanged
IfTrue
, then default values for string/bytes/fixed schemas are passed back unmodified (may not be a string), otherwise the relevant JSON decoding is performed. this should probably never be used except for library compatibility reasonsdecimal_check_exp_overflow
IfTrue
, then values encoded in thedecimal
schema will be checked to ensure they are within the range of the specified precision/scale, otherwise an error is raised.types_str_to_schema
IfTrue
, then callingstr(‹schema instance›)
returns a JSON representation of the schema, otherwise the defaultstr
implementation is used.logical_types
A tuple of logical types to use when parsing schemas, each item must be an instance ofLogicalType
.
Typically this means that for custom logical types, you should subclasscavro.CustomLogicalType
and implementdef custom_encode_value(value)
anddef custom_decode_value(value)
. To add types to this tuple, use thewith_logical_types
method.adapt_record_types
IfTrue
, then when encoding records, if a record type is passed that has come from a different schema, then the record type is adapted to the current schema, provided the name and fields match. This situation can easily occur if a source schema is parsed twice. Each instance of the schema will have its own version of the Record class, and these are not compatible without this option.return_uuid_object
IfTrue
, then UUID values are returned asuuid.UUID
objects, otherwise they are returned as strings.allow_error_type
IfTrue
, then theerror
type is allowed in schemas (As an alias for 'record').allow_leading_dot_in_names
IfTrue
, then names can start with a dot, indicating the null namespace, otherwise an error is raised.naive_dt_assume_utc
IfTrue
, then naive datetime values are assumed to be in UTC, otherwise they are treated as representing local time (using current locale)alternate_timestamp_millis_encoding
IfTrue
, then an alternate approach to encoding timestamps is used that has slightly different behaviour at extreme values.date_type_accepts_string
IfTrue
, then thedate
logical type will accept string in ISO8601 format as input (YYYY-MM-DD), otherwise an error is raised.raise_on_invalid_logical
IfTrue
, then attempts to parse a schema that contain invalid logical decimal paramters, will raise an error, rather than silently ignoring the logical type (as per spec)inline_namespaces
IfTrue
, then when outputting schema JSON from a parsed schema, namespaces are inlined into the name, otherwise the namespace is output as a separate field.expand_types_in_schema
IfTrue
, then when outputting schema JSON from a parsed schema, repeated types are output in full, rather than being referenced by name. Note: This does not apply to nested/recursive types, which are always referenced by name to prevent infinite recursion.unicode_errors
The error handling strategy to use when decoding strings/bytes. See theerrors
parameter tostr.decode
for details.container_fill_blocks
IfTrue
, then when writing a container, records are written until the current block is ›max_blocksize
(I.e. blocks will often be larger thanmax_blocksize
) By default, container writer will write a new block whenever the next record will take the current block over themax_blocksize
, meaning that blocks will always be ‹=max_blocksize
unless a single value is larger thanmax_blocksize
defer_schema_promotion_errors
cavro
performs eager promotion calculation for performance reasons, this means that incompatible reader/writer schemas are typically detected at schema parse time, and errors raised. For compatibility purposes, setting this option toTrue
results in schema promotion errors being stored and raised when the first value is read.invalid_value_includes_record_name
When raising exceptions based on Invalid Values, the exception path includes the name of the record type, rather than just the field name.invalid_value_include_array_index
When raising exceptions based on Invalid Values, the exception path includes the array index of any arraysinvalid_value_include_map_key
When raising exceptions based on Invalid Values, the exception path includes the key of any maps in the valueallow_invalid_default_values
Typically, default values must be valid JSON values for the schema, setting this option toTrue
allows invalid default values to be used (JSON decoding is still performed, but decode errors result in the raw value being used).externally_defined_types
An immutable dict of named types (instances ofAvroType
) that are defined outside of the schema being parsed. This allows for custom/complex schema loading patterns where type definitions may be spread across multiple locations. For example, if this dict has{'Foo': ‹RecordType...›}
, then a schema:{"type": "Foo"}
will be parsed to be the passed-in Foo type. To add types to this dict, use thewith_external_types
method. Note: It's possible to end up with some weird situations including infinite recursion when using this option, as it's possible to create reference cycles between schemas resulting in infinite recursion errors.
Members:
init Options(self, /, *args, **kwargs)
method replace(self, **changes) → cavro.Options
Return a copy of the options with the specified fields replaced.
This is a simple wrapper around dataclasses.replace
method with_logical_types(self, *logical_types)
Return a copy of the options with additional logical types added.
method with_external_types(self, named_types: dict[str, cavro.AvroType]) → cavro.Options
Return a copy of the options with pre-parsed external named types added (Allows for references to types in the schema that have not been defined in the schema)
method equals( self, other: cavro.Options, ignore: collections.abc.Sequence[str] = () ) → bool
Compares two Options objects, this is equivalent to
self == other
except you can pass in a list of field names to ignore
method diff( self, other: cavro.Options, ignore: collections.abc.Sequence[str] = () ) → dict[str, tuple[object, object]]
Returns a dictionary containing just the fields that are different between two Options objects.
Any fields whose names are in ignore
are not included.
The return dictionary is of the form: {field_name: (self_value, other_value)}
attr name_pattern
Returns the relevant regular expression for validating names based on the current options.
attr fingerprint_returns_digest
attr canonical_form_repeat_fixed
attr canonical_form_repeat_enum
attr record_can_encode_dict
attr record_values_type_hint
attr record_decodes_to_dict
attr record_allow_extra_fields
attr record_encode_use_defaults
attr allow_tuple_notation
attr union_decodes_to
attr union_json_encodes_type_name
attr allow_primitive_name_collision
attr allow_primitive_names_in_namespaces
attr named_type_names_must_be_unique
attr enum_symbols_must_be_unique
attr enforce_enum_symbol_name_rules
attr enforce_type_name_rules
attr enforce_namespace_name_rules
attr record_fields_must_be_unique
attr ascii_name_rules
attr missing_values_can_be_null
attr missing_values_can_be_empty_container
attr allow_false_values_for_null
attr allow_empty_unions
attr allow_nested_unions
attr allow_duplicate_union_types
attr allow_union_default_any_member
attr allow_aliases_to_be_string
attr coerce_values_to_int
attr coerce_values_to_float
attr coerce_int_to_float
attr coerce_values_to_boolean
attr coerce_values_to_str
attr bytes_codec
attr fixed_codec
attr null_pad_fixed
attr truncate_fixed
attr clamp_int_overflow
attr clamp_float_overflow
attr float_out_of_range_inf
attr bytes_default_value_utf8
attr string_types_default_unchanged
attr decimal_check_exp_overflow
attr types_str_to_schema
attr logical_types
attr adapt_record_types
attr return_uuid_object
attr allow_error_type
attr allow_leading_dot_in_names
attr naive_dt_assume_utc
attr alternate_timestamp_millis_encoding
attr date_type_accepts_string
attr raise_on_invalid_logical
attr inline_namespaces
attr expand_types_in_schema
attr unicode_errors
attr container_fill_blocks
attr defer_schema_promotion_errors
attr invalid_value_includes_record_name
attr invalid_value_include_array_index
attr invalid_value_include_map_key
attr allow_invalid_default_values
attr externally_defined_types
class ContainerReader
A class for reading avro object container files.
The container can ben used as an iterator, in which case it will yield the objects in the file in order:
for obj in ContainerReader('file.avro'):
print(obj)
Arguments:
src
: The source to read from. Can be a file-like object, instance ofcavro.MemoryReader
, or a path to a file (str|Path)reader_schema
: The schema to use when reading objects. If not provided, the writer schema will be used.options
: An Options object to use when constructing the writer schema. Defaults to the default options. This does not affect thereader_schema
options.
Members:
init ContainerReader(self, /, *args, **kwargs)
attr metadata
attr marker
attr writer_schema
attr reader_schema
attr schema
attr codec_name
attr objects_left_in_block
method next_object(self)
class ContainerWriter
A class for writing avro object container files.
The writer can be used as a context manager, in which case it will be closed when the context exits:
with ContainerWriter('file.avro', schema) as writer:
writer.write_one(obj)
Arguments:
dest
: The destination to write to. Can be a file-like object, instance ofcavro.MemoryWriter
, or a path to a file (str|Path)schema
: The schema of the objects to be written.codec
: The codec to use. Must be one of the supported codecs. Default tonull
max_blocksize
: The maximum size of a block. Defaults to16352
.write_header
: Whether to write the avro header to the file before writing blocks. Defaults toTrue
.metadata
: A dictionary of metadata to write to the file. Defaults to an empty dictionary.marker
: A 16-byte marker to use to separate blocks. Defaults to a random UUID.options
: An Options object to use when writing. Defaults to the default options.
Members:
method close(self)
method flush(self, force=False)
method write_many(self, objs)
attr closed
attr schema
attr codec
attr marker
attr max_blocksize
attr options
attr should_write_header
attr num_pending
attr blocks_written
attr metadata
method write_one(self, obj)
class FileReader
A cavro wrapper for reading data from a file-like object (Object that implements .read(n)
).
This class will not close or seek the underlying file object
Arguments:
file_obj
: The file-like object to read from.
Members:
init FileReader(self, /, *args, **kwargs)
class FileWriter
A cavro wrapper for writing data to a file-like object (Object that implements .write(data)
and .flush()
).
This class will not close or seek the underlying file object
Members:
init FileWriter(self, /, *args, **kwargs)
Other Classes
class MemoryWriter
A class that writes to a memory buffer. The buffer is automatically resized to fit the data.
The underlying data is accessible through the buffer
attribute as an array.array
of bytes.
Members:
attr buffer
attr len
class MemoryReader
A class that allows cavro to read binary data from a memory buffer.
Arguments:
- data: The data to read from. Can be a
bytes
object or amemoryview
.
Members:
init MemoryReader(self, /, *args, **kwargs)
class Rabin
An implementation of the 64-bit Rabin hash function as described in the avro specification.
The interface in this class roughly approximates the hashlib.hash
objects.
Members:
init Rabin(self, /, *args, **kwargs)
method digest(self)
method hexdigest(self)
method copy(self)
attr value
attr name
attr digest_size
attr block_size
method update(self, data)
class Record
An instance of a record value from a schema.
This class should never be instantiated directly, instead it forms the base-class for RecordType.record
classes.
Field values can be accessed using dot notation, e.g. record.field_name
, index notation, e.g. record['field_name']
, or by calling _asdict()
Subclasses of record have a class attribute: Type
, which is the RecordType
schema that the record was created from.
Internally, records are represented as a list of values, one for each field in the record, with associated field metadata. Subclasses can be instantiated in the following ways:
Record(data: list|tuple)
: The length of data must match the number of fields in the record, and each value should correspond to the relevant field valueRecord(data: dict)
: The keys of the dict must match the field names, and each value should correspond to the relevant field valueRecord(data: Record)
: The record must be of the same type as the subclass, or must be adaptable to the subclass (Matching name and fields)Record(**kwargs)
: Each keyword argument should correspond to a field name, and the value should correspond to the relevant field value
Members:
init Record(self, /, *args, **kwargs)
class RecordField
Holds the metadata for a record schema field.
This class should never be instantiated directly, instead it is created by RecordType
when parsing a schema.
Members:
init RecordField(self, /, *args, **kwargs)
method get_schema(self, created)
attr name
attr writer_name
attr doc
attr type
attr default_value
attr order
attr aliases
class AvroType
The base class for all Avro types.
cavro
separates the concept of a Schema
from a Type
, which is not strictly neccessary, but
makes some management of state a bit easier.
Here, a Type
is the specific implementation of the data management, whereas a Schema
is the
public interface for a schema definition, typically (but not always) containing multiple types either in unions or in nested record fields.
For normal usage, the AvroType
class and subclasses can largely be ignored.
Members:
init AvroType(self, /, *args, **kwargs)
method for_source(cls, schema, source, namespace=None)
method for_schema(cls, schema)
method walk_types(self, visited)
attr type
attr options
attr metadata
attr value_adapters
attr type_name
method copy(self)
method convert_value(self, value, check_value=False)
method get_schema(self, created=None)
class UnionType
The avro union type
Members:
init UnionType(self, /, *args, **kwargs)
method walk_types(self, visited)
attr union_types
attr by_name_map
attr return_type_tuple
attr type_name
method copy(self)
method get_schema(self, created=None)
method convert_value(self, value, check_value=True)
class StringType
The avro string type
Members:
attr type_name
method copy(self)
class BytesType
The avro bytes type
Members:
attr type_name
method copy(self)
class DoubleType
The avro double type.
Members:
attr type_name
method copy(self)
class FloatType
The avro float type.
Members:
attr type_name
method copy(self)
class LongType
The avro long type.
Members:
attr type_name
method copy(self)
class IntType
The avro int type.
Members:
attr type_name
method copy(self)
class BoolType
The avro boolean type.
Members:
attr type_name
method copy(self)
class NullType
The avro null type.
Members:
attr type_name
method copy(self)
class MapType
The avro map type.
Members:
init MapType(self, /, *args, **kwargs)
method walk_types(self, visited)
attr value_type
attr type_name
method copy(self)
method convert_value(self, orig_value, check_value=True)
class ArrayType
The avro array type.
Members:
init ArrayType(self, /, *args, **kwargs)
method walk_types(self, visited)
attr item_type
attr type_name
method copy(self)
method convert_value(self, value, check_value=True)
class FixedType
The avro fixed type
Members:
init FixedType(self, /, *args, **kwargs)
attr size
attr type_name
method copy(self)
class RecordType
The Type that corresponds to a Record in a Schema.
Attributes:
doc
Any "doc" metadata defined in the schemafields
A tuple ofRecordField
instances, one for each field in the recordrecord
A subclass ofRecord
that can be used to instantiate records of this type
Members:
init RecordType(self, /, *args, **kwargs)
method walk_types(self, visited)
attr doc
attr fields
attr record
attr type_name
method copy(self)
class PromotingRecordType
A variant of a RecordType
, specialized for reading records from a different schema from a writer.
Members:
class EnumType
The avro enum type
Members:
init EnumType(self, /, *args, **kwargs)
attr symbols
attr default_value
attr doc
attr type_name
method copy(self)
class PromotingEnumType
The avro enum type
Members:
attr unknown_symbols
attr reader_type
attr writer_type
class ResolvedSchema
A variant of a schema that is the result of schema promotion.
Members:
init ResolvedSchema(self, /, *args, **kwargs)
class ValueAdapter
Abstract base class for any helper that affects how values are transformed prior to avro encoding/decoding.
Members:
class LogicalType
Semi-abstract class for all logical types.
Subclasses must be implemented as cython classes.
Members:
method for_type(unknown)
attr logical_name
attr underlying_types
class CustomLogicalType
Logical type that allows custom encoding/decoding functions to be provided.
To use a custom logical type, subclass this class, and implement the:
encode_value(value: object) → object
- Transforms a provided value into something that can be encoded by the underlying type.decode_value(value: object) → object
- Transforms a value decoded by the underlying type into a value to return to the user. methods.
Also implement two class attributes, and a classmethod:
logical_name
- The name to look for in the schemaunderlying_types
A tuple ofAvtoType
classes that this logical type can be applied to._for_type(cls, underlying: AvroType) → Cls
A classmethod that returns an instance of the class, optionally customized with information from the underlying type, or None if the logical type is not applicable to the underlying type.
Members:
class DecimalType
Logical type for decimal values.
Members:
init DecimalType(self, /, *args, **kwargs)
attr type_name
attr precision
attr scale
attr scale_val
attr context
attr size
attr check_exp_overflow
attr logical_name
attr underlying_types
class UUIDBase
Logical type for UUID values
Members:
init UUIDBase(self, /, *args, **kwargs)
attr logical_name
class UUIDStringType
Logical type for UUID values
Members:
attr type_name
attr underlying_types
class UUIDFixedType
Logical type for UUID values
Members:
attr type_name
attr underlying_types
class Date
Logical type for Date values
Members:
init Date(self, /, *args, **kwargs)
attr type_name
attr accepts_string
attr logical_name
attr underlying_types
class TimeMillis
Logical type for time-millis values
Members:
attr type_name
attr logical_name
attr underlying_types
class TimeMicros
Logical type for time-micros values
Members:
attr type_name
attr logical_name
attr underlying_types
class TimestampMillis
Logical type for timestamp-micros values
Members:
init TimestampMillis(self, /, *args, **kwargs)
attr type_name
attr alternate_timestamp_encoding
attr logical_name
attr underlying_types
class TimestampMicros
Logical type for timestamp-micros values
Members:
attr type_name
attr logical_name
attr underlying_types
class Codec
Abstract base class for all codecs. This class is not meant to be used directly.
Subclasses must be implemented in cython.
Members:
attr name
class PromoteToFloat
A value adapter that converts a value to a float on read.
Members:
class PromoteBytesToString
A value adapter that decodes bytes to a string (utf8) on read.
Members:
class PromoteStringToBytes
A value adapter that encodes a string to bytes (utf8) on read.
Members:
class CannotPromote
A captured schema promotion error that has been deferred by Options
, the first time this value is read, the error will be raised.
Members:
init CannotPromote(self, /, *args, **kwargs)
attr reader_type
attr writer_type
attr extra
class CavroException
Base class for exceptions raised by cavro
Members:
class InvalidName
The schema contains a type or enum symbol with an invalid name (as per the avro specification)
Members:
class UnknownType
The schema contains an unexptected type name (either a missing named-type definition, or invalid primitive type)
Members:
init UnknownType(self, name)
class DuplicateName
A record contains multiple fields with the same name, a schema contains multiple types of the same name, or an enum has multiple identical symbols.
Members:
class InvalidHasher
An unknown hash method was requested
Members:
class ExponentTooLarge
The exponent of a decimal value is too large to be represented in the given type
Members:
class CodecUnavailable
A requested codec (or codec in a container) is not available or is unknown.
Members:
class CannotPromoteError
A schema cannot be promoted to another schema. (reader/writer schema promotion)
Attributes:
reader_type
: The schema type of the readerwriter_type
: The schema type of the writerextra
: An optional extra message
Members:
init CannotPromoteError(self, reader_type, writer_type, extra=None)
class InvalidValue
A value is invalid for a given avro type.
Attributes:
value
: The value that caused the errordest_type
: The schema type that the value was being converted toschema_path
: A sequence of identifiers (field names etc) to help locate the value that caused the error
Members:
init InvalidValue(self, value, dest_type, path=())
class UnionDecodeOption
Controls how union values are decoded:
- RAW_VALUES - The value of the matching union type is returned unmodified
- TYPE_TUPLE_IF_AMBIGUOUS - If union contains types that might be ambiguous (Record + Map) or (String + Enum), then the value is returned as a 2-tuple of (‹type›, ‹value›)
- TYPE_TUPLE_IF_RECORD_AMBIGUOUS - If union contains multiple record (or map) types, then the value is returned as a 2-tuple of (‹type›, ‹value›)
- TYPE_TUPLE_IF_RECORD - values matching any union member that is record are returned as a 2-tuple of (‹type›, ‹value›)
- TYPE_TUPLE_ALWAYS - values are always returned as a 2-tuple of (‹type›, ‹value›)
Members:
attr RAW_VALUES
attr TYPE_TUPLE_IF_AMBIGUOUS
attr TYPE_TUPLE_IF_RECORD_AMBIGUOUS
attr TYPE_TUPLE_IF_RECORD
attr TYPE_TUPLE_ALWAYS
class Order
The order of a field in a record.