Skip to main content

Light tool for compiling avro schema files (.avsc) to python classes making using avro schemata easy.

Project description

avro-to-python-etp is a light tool for compiling avro schema files (.avsc) to python classes making using avro schemata easy.

Installation

Install From Source ()

The sources for avro-to-python-etp can be downloaded source as well.

Clone the public repository:

$ git clone git://github.com/srserves85/avro-to-python-etp

Once you have a copy of the source, you can install it with:

$ python setup.py install

or

$ pip install -e .

Examples

Majority of the use of avro-to-python-etp is assumed to be used as a cli, but you can still import and use the python classes under the hood as well.

CLI (without –pip)

To use the cli, here is the available cli commands:

avro-to-python-etp [source] [target]
    Options:
        --pip TEXT              make package pip installable using this name
        --author TEXT           author name of the pip installable package
        --package_version TEXT  version of the pip intallable package  [default: 0.1.0]
        --help                  Show this message and exit

The above will compile the avsc files and convert the to python classes found in [path_to_target_directory]

An example of doing this is the following:

avro-to-python-etp [path_to_source_avsc_files] [path_to_target_directory]

If you run the above on a valid avro avsc file, you should then be able to import them as you would in the avro idl namespace Here is an example of a single avsc record from the namespace: name.space and name: RecordClass:

from name.space import RecordClass

record = RecordClass({'foo': True, 'bar': 'true', 'baz': 10, 'food': 'CHOCOLATE'})

CLI (with –pip)

You can also choose to make compiled avro packages *pip installable* by adding the “–pip” flags. An example of this is the following: .. code-block:: bash

avro-to-python-etp [path_to_source_avsc_files] [path_to_target_directory] –pip test_avro

By running this, you should be able to pip install the above package you created from the target directory you specified by running:

pip install -e path_to_target_directory

Now that you have the package installed, you can import it by it’s package name and namespace. Here is the same example of the same avsc from above, only with a pip package of test_avro:

from test_avro.name.space import RecordClass

record = RecordClass({'foo': True, 'bar': 'true', 'baz': 10, 'food': 'CHOCOLATE'})

avro-to-python-etp in a Script

You can also use the reader and writer packages in avro-to-python-etp as you would any other python package. Avro to python is split between a reader and writer classes. avro-to-python-etp treates namespaces as acyclic trees and uses depth first search to ensure no duplication or namespace collisions on read and write. An example useage is below:

from avro_to_python.reader import AvscReader
from avro_to_python.writer import AvroWriter

# initialize the reader object
reader = AvscReader(directory='tests/avsc/records/')

# generate the acyclic tree object
reader.read()

# initialize the writer object
writer = AvroWriter(reader.file_tree, pip='test_pip')

# compile python files using 'tests/test_records as the namespace root'
writer.write(root_dir='tests/test_records')

Roadmap

Reader

  • [X] Create Namespace Trees on nested namespaces

  • [X] Read Record and Enum File

  • [X] Primitive types

  • [X] Array Types

  • [X] Union types

  • [X] References to other files

  • [X] Map Types

  • [ ] Logical Types (Currently just converts to primitive types)

Writer

  • [X] Base Schema Writer

  • [X] Base Record Schema

  • [X] Base Enum Schema

  • [X] Primitive Types Schema

  • [X] Array Types Schema

  • [X] Union Types Schema

  • [X] Map Types

  • [ ] Logical Types Schema (Currently just converts to primitive types)

  • [X] Add configs to pip install package

CLI

  • [X] Wrap Writer and Reader into one cli commmit

  • [X] Add pip install option (would include all files to pip install compiled package)

  • [ ] Add better –help documentation

Documentation

  • [ ] Document reader class

  • [ ] Document writer class

  • [ ] Document cli

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

avro_to_python_etp-1.0.11.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

avro_to_python_etp-1.0.11-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file avro_to_python_etp-1.0.11.tar.gz.

File metadata

  • Download URL: avro_to_python_etp-1.0.11.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.9.21 Linux/6.8.0-1021-azure

File hashes

Hashes for avro_to_python_etp-1.0.11.tar.gz
Algorithm Hash digest
SHA256 6923a78e40d988f7e0c45e493b8492194da334b56daaacc807e0bd1686387d0b
MD5 fc24e63f9532356b0bd4bd9e025a5509
BLAKE2b-256 5fd3048461002f40847d487acdeb6848ef7597170daf7b9ea5216c5ef4fe0617

See more details on using hashes here.

File details

Details for the file avro_to_python_etp-1.0.11-py3-none-any.whl.

File metadata

  • Download URL: avro_to_python_etp-1.0.11-py3-none-any.whl
  • Upload date:
  • Size: 43.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.9.21 Linux/6.8.0-1021-azure

File hashes

Hashes for avro_to_python_etp-1.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 d219eaff164fdb07e36d67e9c28bf137d54de01a16aaa372d0e5319e04b6874f
MD5 8025272c1b4a1ac45070480c24aeafc2
BLAKE2b-256 7cc7f44b9804f6e35d897f40226ce2301d13bd61eabb806eb30b2d776ed331c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page