fastavro.read

class reader(fo, reader_schema=None)

Iterator over records in an avro file.

Parameters:
  • fo (file-like) – Input stream
  • reader_schema (dict, optional) – Reader schema

Example:

from fastavro import reader
with open('some-file.avro', 'rb') as fo:
    avro_reader = reader(fo)
    schema = avro_reader.schema
    for record in avro_reader:
        process_record(record)
class block_reader(fo, reader_schema=None)

Iterator over blocks in an avro file.

Parameters:
  • fo (file-like) – Input stream
  • reader_schema (dict, optional) – Reader schema

Example:

from fastavro import block_reader
with open('some-file.avro', 'rb') as fo:
    avro_reader = block_reader(fo)
    schema = avro_reader.schema
    for block in avro_reader:
        process_block(block)
schemaless_reader(fo, writer_schema, reader_schema=None)

Reads a single record writen using the schemaless_writer

Parameters:
  • fo (file-like) – Input stream
  • writer_schema (dict) – Schema used when calling schemaless_writer
  • reader_schema (dict, optional) – If the schema has changed since being written then the new schema can be given to allow for schema migration

Example:

with open('file.avro', 'rb') as fp:
    record = fastavro.schemaless_reader(fp, schema)

Note: The schemaless_reader can only read a single record.

is_avro(path_or_buffer)

Return True if path (or buffer) points to an Avro file.

Parameters:path_or_buffer (path to file or file-like object) – Path to file