Skip to main content

Generate Avro Schemas from a Python class

Project description

Dataclasses Avro Schema Generator

Generate Avro Schemas from a Python class

Build Status GitHub license codecov python version

Requirements:

python 3.7+

Installation

pip install dataclasses-avroschema

Documentation

https://marcosschroh.github.io/dataclasses-avroschema/

Usage:

from dataclasses_avroschema.schema_generator import SchemaGenerator


class User:
    "An User"
    name: str
    age: int
    pets: typing.List[str]
    accounts: typing.Dict[str, int]
    favorite_colors: typing.Tuple[str] = ("BLUE", "YELLOW", "GREEN")
    country: str = "Argentina"
    address: str = None

SchemaGenerator(User).avro_schema()

'{
    "type": "record",
    "name": "User",
    "doc": "An User",
    "fields": [
        {"name": "name", "type": "string"},
        {"name": "age", "type": "int"},
        {"name": "pets", "type": "array", "items": "string"},
        {"name": "accounts", "type": "map", "values": "int"},
        {"name": "favorite_colors", "type": "enum", "symbols": ["BLUE", "YELLOW", "GREEN"]},
        {"name": "country", "type": ["string", "null"], "default": "Argentina"},
        {"name": "address", "type": ["null", "string"], "default": "null"}
    ]
}'

Features:

  • [X] Primitive types: int, long, float, boolean, string and null support
  • [X] Complex types: enum, array, map, unions and records support
  • [x] Logical Types: date, time, datetime, uuid support
  • [X] Schema relations (oneToOne, oneToMany)
  • [X] Recursive Schemas
  • [X] Generate Avro Schemas from faust.Record

Project details


Download files

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

Files for dataclasses-avroschema, version 0.8.0
Filename, size File type Python version Upload date Hashes
Filename, size dataclasses-avroschema-0.8.0.tar.gz (10.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page