Giter Site home page Giter Site logo

avroc's Introduction

avroc

avroc is a Python just-in-time compiler for reading and writing Avro data.

It aims to be:

  • Completely correct to the Avro specification.
  • Very, very fast when compiled. Our goal is to be the fastest library available in Python for dealing with Avro.
  • Ergonomic and simple to use, with a small API that's clear.

You can read more in this blog post.

Installation

Install with pip:

pip install avroc

Basic usage

import avroc

# Make up a schema
schema = {
    "type": "record",
    "name": "Weather",
    "fields": [
        {"name": "temperature", "type": "double"},
        {"name": "wind_speed", "type": "double"},
        {"name": "location", "type": "string"},
    ]
}

# Make up some records
records = [
    {"temperature": 71.2, "wind_speed": 0.5, "location": "San Diego"},
    {"temperature": 8.2, "wind_speed": 13.4, "location": "North Pole"},
    {"temperature": -66.0, "wind_speed": 14.4, "location": "Mars"},
]

# Write records to a file
with open("data.avro, "wb") as f:
    avroc.write_file(f, schema, records)

# Read records from a file
with open("data.avro", "rb") as f:
    for msg in avroc.read_file(f):
        print(f'The temperature in {msg["location"]} is {msg["temperature"]}')

# Encode a single record as raw bytes
encoder = avroc.compile_encoder(schema)
raw_bytes = encoder(records[0])

# Decode a raw bytes as a single record
decoder = avroc.compile_decoder(schema)
rec = decoder(io.BytesIO(raw_bytes))

For a lot more detail, see the documentation: avroc.readthedocs.io

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.