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

Doocumentaion

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:

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

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

dataclasses-avroschema-0.7.1.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file dataclasses-avroschema-0.7.1.tar.gz.

File metadata

  • Download URL: dataclasses-avroschema-0.7.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.0

File hashes

Hashes for dataclasses-avroschema-0.7.1.tar.gz
Algorithm Hash digest
SHA256 befe14f8db256488fbd8cbe4f66952dd4cf7bd574708dabd42b8ad5bf9cb3c76
MD5 2e9394a9ce2c93ca7567394690c7eab7
BLAKE2b-256 5f49ecd8b3acf7b2328e04174a15ec10f98986fb57e54c55c68cbb74776617a5

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