Skip to main content

Async Kafka foundation library — factories, settings, DI providers and OpenTelemetry on top of aiokafka

Project description

aiokafka-foundation-kit

PyPI Python License CI codecov Docs

Async Kafka foundation library with producer, consumer, metrics, and Dishka providers built on aiokafka.

Features

  • 🚀 AsyncIO-first: Built on top of aiokafka for high-performance async operations
  • 📊 Observability: Built-in Prometheus metrics and OpenTelemetry support
  • 🔧 Pydantic Settings: Type-safe configuration with Pydantic
  • 💉 Dishka Integration: Dependency injection providers for easy integration
  • 🔄 Retry Logic: Configurable retry policies with tenacity
  • 🏥 Health Checks: Kafka cluster health monitoring
  • 📝 Topic Management: Automatic topic creation and management
  • 🎯 Type-Safe: Full type annotations with mypy strict mode

Installation

# Core functionality
pip install aiokafka-foundation-kit

# With all optional dependencies
pip install aiokafka-foundation-kit[all]

# Or specific features
pip install aiokafka-foundation-kit[models,orjson,dishka,dependency-injector,telemetry]

Quick Start

Producer Example

from aiokafka_foundation_kit import (
    BaseKafkaProducerSettings,
    AsyncKafkaPublisher,
    create_async_kafka_producer,
)

# Configure
settings = BaseKafkaProducerSettings(
    bootstrap_servers="localhost:9092",
)

# Create producer
producer = create_async_kafka_producer(settings)
await producer.start()

# Create publisher
publisher = AsyncKafkaPublisher(producer)
await publisher.start()

# Publish
await publisher.publish(
    topic="events",
    value={"event": "user_created", "user_id": "123"},
    event_type="user_created",
)

Consumer Example

from aiokafka_foundation_kit import (
    BaseKafkaConsumerSettings,
    AsyncKafkaConsumerRunner,
    create_async_kafka_consumer,
)

# Configure
settings = BaseKafkaConsumerSettings(
    bootstrap_servers="localhost:9092",
    group_id="my-group",
)

# Create consumer
consumer = create_async_kafka_consumer(settings, topics=["events"])
client = AsyncKafkaConsumerClient(consumer)
await client.start()

# Handle messages
async def handle(message):
    print(f"Received: {message.value}")

runner = AsyncKafkaConsumerRunner(client, handle)
await runner.start()

Documentation

Full documentation at bedrock-python.github.io/aiokafka-foundation-kit.

Development

# Install dependencies
uv sync --group dev

# Run tests
make test

# Run linter
make lint

# Format code
make fmt

License

Apache 2.0 — see LICENSE for details.

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

aiokafka_foundation_kit-0.1.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

aiokafka_foundation_kit-0.1.0-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

Details for the file aiokafka_foundation_kit-0.1.0.tar.gz.

File metadata

  • Download URL: aiokafka_foundation_kit-0.1.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiokafka_foundation_kit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6df88d8eed9928cb1c7911d01322ad759364771ba2209b75656a22b9ba053f2b
MD5 2d5a83e94115aa17b4d7490847123e7f
BLAKE2b-256 fa149cb97a9f1ba4349ca2e0963b797dff0d0c9d3af57bd30e6d439ce459f6d4

See more details on using hashes here.

File details

Details for the file aiokafka_foundation_kit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aiokafka_foundation_kit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 37.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aiokafka_foundation_kit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68578ef4f65c149d1900b9211e26d869084b574182dd3e8f9b5239095daf4839
MD5 bb11af39cc130ed9bb4d54933fd5fd48
BLAKE2b-256 968043891e767cfbde2c5ee57bb9c95a711063aeb95c8127a4040da9c60196cc

See more details on using hashes here.

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