Skip to main content

Apache Avro serialization/deserialization with Confluent Schema Registry framing and Apicurio integration

Project description

AvroCurio

Apache Avro serialization/deserialization with Confluent Schema Registry framing using Apicurio Schema Registry.

Installation

Using uv, poetry, or pip:

uv add avrocurio
poetry add avrocurio
pip install avrocurio

Quick Start

1. Define your schema using dataclasses-avroschema

from dataclasses import dataclass
from dataclasses_avroschema import AvroModel

@dataclass
class User(AvroModel):
    name: str
    age: int
    email: str

2. Serialize and deserialize data

import asyncio
from avrocurio import AvroSerializer, ApicurioClient, ApicurioConfig

async def main():
    # Configure connection to Apicurio Registry
    config = ApicurioConfig(base_url="http://localhost:8080")

    # Create client and serializer
    async with ApicurioClient(config) as client:
        serializer = AvroSerializer(client)

        # Create a user instance
        user = User(name="John Doe", age=30, email="john@example.com")

        # Serialize the user to an Avro binary with Confluent registry framing.
        # Under the hood this will perform a lookup against Apicurio to get the
        # artifact ID for the schema, which is then prepended to the Avro binary
        # (along with a magic byte).
        serialized = await serializer.serialize(user)

        # Deserialize the binary back to a User instance.
        deserialized_user = await serializer.deserialize(serialized, User)

asyncio.run(main())

Confluent Schema Registry Wire Format

AvroCurio implements the Confluent Schema Registry wire format:

+----------------+------------------+------------------+
| Magic Byte     | Schema ID        | Avro Payload     |
| (1 byte = 0x0) | (4 bytes, BE)    | (remaining)      |
+----------------+------------------+------------------+
  • Magic Byte: Always 0x0 to identify Confluent wire format
  • Schema ID: 4-byte big-endian integer referencing the schema in the registry
  • Avro Payload: Standard Avro binary-encoded data

Schema Caching

Schema caching is handled automatically by the ApicurioClient for performance.

Development

Requirements

Integration tests require a running Apicurio Registry. Running it through Docker or Podman using Compose is easiest:

docker compose up

Port 8080 is assumed by default, but you can set APICURIO_URL to point to a different instance.

Running Tests

# Run all tests
uv run pytest

# Run specific test file
uv run pytest tests/test_serializer.py

# Run with verbose output
uv run pytest -v

# Skip integration tests
uv run pytest -m "not integration"

License

AvroCurio is open-source software released under the BSD-2-Clause Plus Patent License. This license is designed to provide: a) a simple permissive license; b) that is compatible with the GNU General Public License (GPL), version 2; and c) which also has an express patent grant included.

Please review the LICENSE file for the full text of the license.

Project details


Download files

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

Source Distribution

avrocurio-1.2.1.tar.gz (88.3 kB view details)

Uploaded Source

Built Distribution

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

avrocurio-1.2.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file avrocurio-1.2.1.tar.gz.

File metadata

  • Download URL: avrocurio-1.2.1.tar.gz
  • Upload date:
  • Size: 88.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for avrocurio-1.2.1.tar.gz
Algorithm Hash digest
SHA256 9028c433a77823fb00f1ca53abec7dab8d99a7325c238ecba599a24bb5c0b282
MD5 d4ad35f6deefc7e29a1b1eb1e2777cef
BLAKE2b-256 9e3a0d9efd2e1db1f8124a8b7ea225bb18fa4fe39c06555c6d9b276ab4218f12

See more details on using hashes here.

Provenance

The following attestation bundles were made for avrocurio-1.2.1.tar.gz:

Publisher: release.yml on castoredc/avrocurio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file avrocurio-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: avrocurio-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for avrocurio-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4405a64d7dc1f506b581a98d0791f306ef91bff9ae31e95f4e72629f93eb495f
MD5 207b5a89c430e040a5f175751ad2a616
BLAKE2b-256 ec78bae8a20a3e867f1b0b1f8814d96112848c70c030eb95dc392b4b4173da87

See more details on using hashes here.

Provenance

The following attestation bundles were made for avrocurio-1.2.1-py3-none-any.whl:

Publisher: release.yml on castoredc/avrocurio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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