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

Download files

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

Source Distribution

pydantic_avro-0.11.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_avro-0.11.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_avro-0.11.0.tar.gz.

File metadata

  • Download URL: pydantic_avro-0.11.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pydantic_avro-0.11.0.tar.gz
Algorithm Hash digest
SHA256 18e4f54de1fabec837003d83d5cb4ef6db47fb41600affb230eaa7d386ca1f11
MD5 3bd999add49e102f5a45d87e5875e0c8
BLAKE2b-256 b779a94e05b3eccfac7efb478043f26520539095374b011fc6166a557e4f97d6

See more details on using hashes here.

File details

Details for the file pydantic_avro-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic_avro-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pydantic_avro-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ade496e65973cdebb41dd6aa78dfe35712e1c22d7e4120141374262411ca4db5
MD5 3469d561e548de01e187bae5c49f9d8e
BLAKE2b-256 5bd15bae40663afdbd200364dd2603f4b2e487e065052d68f05c1caa6bd962c6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 files

0.10.0

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.5

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 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