API

quickavro.encoder module

class quickavro.encoder.BinaryEncoder(schema=None, codec=’null’)[source]

The object used to implement binary Avro encoding in quickavro. It is used internally and is exposed in the quickavro Python API.

Parameters:
  • schema – (optional) Dictionary to use as Avro schema for this BinaryEncoder.
  • codec – (optional) Compression codec used with BinaryEncoder.

Example:

with quickavro.BinaryEncoder() as encoder:
    encoder.schema = {
      "type": "record",
      "name": "Person",
      "fields": [
        {"name": "name", "type": "string"},
        {"name": "age",  "type": ["int", "null"]}
      ]
    }
    with open("test.avro, "wb") as f:
        f.write(encoder.header)
        for block in encoder.write_blocks(records):
            f.write(block)
quickavro.encoder.read_header(data)[source]

Reads Avro binary file header

Parameters:data – bytes representing Avro file header.
quickavro.encoder.write_header(schema, sync_marker, codec=’null’)[source]

Writes Avro binary file header

Parameters:
  • schema – Dictionary to use as Avro schema.
  • sync_marker – str used to verify blocks.
  • codec – (optional) Compression codec.

quickavro.reader module

class quickavro.reader.FileReader(f, header_size=8192)[source]

The FileReader object implements quickavro.BinaryEncoder and provides and interface to read Avro files.

Parameters:f – File-like object or path of file that FileReader will read from.

Example:

with quickavro.FileReader("test.avro") as reader:
    for record in reader.records():
        print(record)

quickavro.writer module

class quickavro.writer.FileWriter(f, codec=’null’)[source]

The FileWriter object implements quickavro.BinaryEncoder and provides and interface to write Avro files.

Parameters:
  • f – File-like object or path of file that FileWriter will write into.
  • codec – (optional) Compression codec used with FileWriter.

Example:

with quickavro.FileWriter("test.avro) as writer:
    writer.schema = {
      "type": "record",
      "name": "Person",
      "fields": [
        {"name": "name", "type": "string"},
        {"name": "age",  "type": ["int", "null"]}
      ]
    }

    records = [
        {"name": "Larry", "age": 21},
        {"name": "Gary", "age": 34},
        {"name": "Barry", "age": 27},
        {"name": "Dark Larry", "age": 1134},
        {"name": "Larry of the Void", "age": None},
    ]

    for record in records:
        writer.write_record(record)