sprockets.mixins.avro

Mixins that make working with Avro data easier.

Version Downloads Status Coverage License

Installation

sprockets.mixins.avro is available on the Python Package Index and can be installed via pip:

pip install sprockets.mixins.avro

Requirements

API Documentation

API Reference

class sprockets.mixins.avro.Decoder

Mix this in over a rejected Consumer for avro deserialization.

This mix-in implements the body property that will automatically deserialize avro datum values using a provided schema. You are required to implement the get_avro_schema() method so that it returns the appropriate avro.schema.Schema instance for this message type.

See also: rejected.consumer.Consumer and rejected.consumer.SmartConsumer

body

Return the fully deserialized message body.

get_avro_schema()

Return the avro schema to use for this message.

Returns:the avro schema instance appropriate to this message
Return type:avro.schema.Schema

Examples

Rejected Consumer

A rejected consumer that automatically decodes and validates messages serialized using Avro.

from pkg_resources import resource_string

from avro import schema
from rejected import consumer
import sprockets.mixins.avro

class MyConsumer(sprockets.mixins.avro.Decoder,
                 consumer.PublishingConsumer):

    def __init__(self, *args, **kwargs):
        super(MyConsumer, self).__init__(*args, **kwargs)
        self._schema = None

    def get_avro_schema(self):
        if self._schema is None:
            schema_string = resource_string('mypackage', 'schema.avsc')
            self._schema = schema.parse(schema_string)

    def process(self):
        # self.body refers to the current message *AFTER*
        # decoding and validating it according to the
        # Avro schema!

Version History

  • 1.0.0 2015-05-12
    • Initial release that includes a Tornado-alike decoder mixin. The mix in is built for use with the rejected framework.

Issues

Please report any issues to the Github project at https://github.com/sprockets/sprockets.mixins.avro/issues

Source

sprockets.mixins.avro source is available on Github at https://github.com/sprockets/sprockets.mixins.avro

License

sprockets.mixins.avro is released under the 3-Clause BSD license.

Indices and tables