Skip to main content

pyavro-gen

Standard Avro implementation for Python is typeless and operates on dicts. While this is convenient for small projects, larger ones, often with hundreds of schemas, certainly benefit from the ability to enforce schemas during record construction.

This library allows Python Avro users to employ Specific Records.

Usage:

pip install pyavro-gen
pyavrogen.py -v \
    -i my_schemas_dir \
    -o jaumoavro \
    -ie 'avsc' \
    -b com.jaumo.schema \
    -r com.jaumo.schema.rpc \
    -t com.jaumo.schema.type

Now you can import your classes like

from jaumoavro.com.jaumo.schema.domain.user import Updated

u = Updated(...)

Generation and test programmatically

from avro_preprocessor.avro_paths import AvroPaths
from pyavro_gen.generator import AvroGenerator

generator = AvroGenerator(
    AvroPaths(
        input_path='myschemas/',
        output_path='avroclasses/',
        input_schema_file_extension='avsc',
        base_namespace='com.jaumo.schema',
        rpc_namespace='com.jaumo.schema.rpc',
        types_namespace='com.jaumo.schema.type',
    )
)
generator.process()

Generation using custom classes:

from pyavro_gen.generation_classes import GENERATION_CLASSES, GenerationClassesType
from pyavro_gen.codewriters.base import Decorator, ClassWriter, Extension
from typing import Optional

# First define two custom ClassWriters

class RpcWriter(ClassWriter):
    def __init__(self,
                 fully_qualified_name: str,
                 doc: Optional[str] = None,
                 prefix: Optional[str] = None):
        super().__init__(fully_qualified_name, doc, prefix)

        self.extensions = [
            Extension('abc.ABC')
        ]


class UndictifiableClassWriter(ClassWriter):
    def __init__(self,
                 fully_qualified_name: str,
                 doc: Optional[str] = None,
                 prefix: Optional[str] = None):
        super().__init__(fully_qualified_name, doc, prefix)

        self.decorators = [
            Decorator('@type_checked_constructor()',
                      ClassWriter('undictify.type_checked_constructor')),
            Decorator('@dataclass', ClassWriter('dataclasses.dataclass'))
        ]


# Then, register them in the GENERATION_CLASSES variable

GENERATION_CLASSES[GenerationClassesType.RECORD_CLASS] = UndictifiableClassWriter
GENERATION_CLASSES[GenerationClassesType.RPC_CLASS] = RpcWriter

# Then, generate classes in module `avroclasses` as shown above.

Metadata

Release files for pyavro-gen 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyavro-gen 0.3.4
File Size Uploaded Provenance Actions
pyavro-gen-0.3.4.tar.gz 17.5 kB Without provenance Details for pyavro-gen-0.3.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyavro-gen 0.3.4
File Interpreter ABI Platform Actions
pyavro_gen-0.3.4-py3-none-any.whl Python 3 none any Details for pyavro_gen-0.3.4-py3-none-any.whl

Total release size: 42.0 kB

Release files / pyavro-gen-0.3.4.tar.gz

Download URL pyavro-gen-0.3.4.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
69cf492ec98d35b2088f9fe1f218bb40b3327b1c5cae7a65196c082052ee3ba3
BLAKE2b-256 checksum
How to use checksums
678717163c7d89b1879382406c78c2bb02f4fcff0c08caf9c097da122f80510f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.13

Release files / pyavro_gen-0.3.4-py3-none-any.whl

Download URL pyavro_gen-0.3.4-py3-none-any.whl
Size 24.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ac2af8787496439a9432477469123aa626d70c6886e30a8f1c1900895d8a6e6
BLAKE2b-256 checksum
How to use checksums
4b6e45febddc21d21974cfb766e163621a2037ce48819bde5bd5286b875a585b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.13

Security for pyavro-gen 0.3.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page