Skip to main content

Python package codecov PyPI version CodeQL

pydantic-avro

This library can convert a pydantic class to a avro schema or generate python code from a avro schema.

Install

pip install pydantic-avro

Pydantic class to avro schema

import json
from typing import Optional

from pydantic_avro.base import AvroBase


class TestModel(AvroBase):
    key1: str
    key2: int
    key2: Optional[str]


schema_dict: dict = TestModel.avro_schema()
print(json.dumps(schema_dict))

Avro schema to pydantic

# Print to stdout
pydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc

# Save it to a file
pydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc --output /path/to/output.py

Specify expected Avro type

from datetime import datetime
from pydantic import Field
from pydantic_avro.base import AvroBase 

class ExampleModel(AvroBase):
    field1: int = Field(..., avro_type="long")  # Explicitly set Avro type to "long"
    field2: datetime = Field(..., avro_type="timestamp-millis")  # Explicitly set Avro type to "timestamp-millis"

Install for developers

Install package
  • Requirement: Poetry 1.*
poetry install
Run unit tests
pytest
coverage run -m pytest  # with coverage
# or (depends on your local env) 
poetry run pytest
poetry run coverage run -m pytest  # with coverage
Run linting

The linting is checked in the github workflow. To fix and review issues run this:

black .   # Auto fix all issues
isort .   # Auto fix all issues
pflake .  # Only display issues, fixing is manual

Metadata

Release files for pydantic-avro 0.12.1

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

Source distribution (sdist)

Source distribution for pydantic-avro 0.12.1
File Size Uploaded
pydantic_avro-0.12.1.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-avro 0.12.1
File Interpreter ABI Platform
pydantic_avro-0.12.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.6 kB

Release files / pydantic_avro-0.12.1.tar.gz

Download URL pydantic_avro-0.12.1.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2bb33eb38036e1d27410c38db750de60e6476fa489b0fd7f4560a9b8ec2b8938
BLAKE2b-256 checksum
How to use checksums
b93fba243829bc2b761342ee65138c5f95ecde0f1185be338557326627e873a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pydantic_avro-0.12.1-py3-none-any.whl

Download URL pydantic_avro-0.12.1-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e6cdb3f50a64c063388cf2fa19ad2ad12c73b8e8a5ca8d67efdef8b8a903dc4
BLAKE2b-256 checksum
How to use checksums
b48ee1e00d55678472a2485fc7c22ac5c7160987101f1c17e1e4486191060d4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.12.1 This release

2 release files

0.11.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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