skillfed

pydantic-avro

Converting pydantic classes to avro schemas

pydantic-avro v0.10.0 2.4M downloads/30d#3,080 on PyPI85
Permissive license MIT Active released

What it is and what it does

pydantic-avro bridges pydantic data models and Apache Avro schemas. It lets you define a pydantic class that inherits from AvroBase, then export it as an Avro schema dictionary for serialization or integration with Avro-based systems. It also works in reverse: you can provide an Avro schema file and generate a pydantic class from it via a command-line tool. The library supports explicit Avro type specification through pydantic Field annotations, so you can control how Python types map to Avro types when the default inference isn't what you need.

The package is lightweight, depending only on pydantic itself. It's useful in data pipelines, message brokers, and systems that need both pydantic's validation and Avro's schema portability. The CLI tool makes it easy to generate boilerplate code from existing Avro schemas without manual translation.

Use it for:

  • Generate Avro schemas from pydantic models for use in Kafka producers or other Avro-based message systems
  • Convert existing Avro schema files into pydantic classes to maintain type safety in Python applications
  • Explicitly map Python datetime fields to Avro timestamp types or other non-default Avro representations
  • Automate schema generation in data pipelines where both validation and schema registry integration are needed

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts between pydantic class definitions and Apache Avro schemas in both directions, enabling serialization and schema generation for data validation workflows.

Yes. Low install friction, active maintenance, no known vulnerabilities, and a permissive MIT license make it a safe choice. Install it if you need bidirectional conversion between pydantic and Avro—either to export pydantic models for Avro systems or to generate pydantic classes from Avro schemas.

Install

pydantic-avro on PyPI

pip

pip install pydantic-avro

uv

uv add pydantic-avro

poetry

poetry add pydantic-avro

Installing pydantic-avro

Before you install

Low install friction with a single runtime dependency on pydantic. Actively maintained with recent commits; last release 189 days ago with an active repository.

License in practice

MIT license permits commercial and private use with minimal restrictions; suitable for most projects without licensing concerns.

Quickstart

pip install pydantic-avro

from pydantic_avro.base import AvroBase

class TestModel(AvroBase):
    key1: str
    key2: int

schema_dict = TestModel.avro_schema()
print(schema_dict)

Verify before relying

  • Whether the package handles complex nested pydantic models and all Avro logical types beyond the examples shown
  • Performance characteristics when converting large or deeply nested schemas
  • Compatibility guarantees with different pydantic versions beyond the implicit dependency

Package facts

License MIT (permissive)
Python support supports the current Python release (<4.0,>=3.8.1)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pydantic
Maintenance actively maintained — 189 days since the last release
Last repo commit
First released
Downloads 2,401,151/month — #3,080 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pydantic_avro-0.10.0-py3-none-any.whl

Keywords: pydantic, avro

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.9

Tags

pydantic to avro schema conversionavro schema to pydantic classavro serialization pydanticdata validation avroschema generation from pydanticavro schema python
schema-generationdata-validationserialization

More Application Frameworks packages