aiokafka-foundation-kit
Async Kafka foundation library — settings, client factories, lifecycle helpers, topic management and DI wiring on top of aiokafka.
Features
- AsyncIO-first — everything is built on
aiokafka; there is no synchronous mirror - Protocol-based config — every entry point takes a
typing.Protocol, so a Pydantic model, a dataclass or a stub all work - Pydantic settings —
BaseKafkaProducerSettings/BaseKafkaConsumerSettingswith validation, via themodelsextra - Lifecycle helpers —
producer_lifecycle/consumer_lifecycleown start and stop, including on failure - Topic management —
ensure_topics_asynccreates topics idempotently before a producer starts - Health checks —
check_kafka_health_asyncprobes broker reachability - JSON serialisation —
dumps_bytes/loads_bytes, with transparentorjsonacceleration - DI integration — Dishka providers and dependency-injector containers
- OpenTelemetry —
instrument_aiokafkawires the aiokafka instrumentor in one call - Type-safe — full annotations, checked with mypy
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
from aiokafka_foundation_kit import TopicConfig, producer_lifecycle
from aiokafka_foundation_kit.contrib.models import BaseKafkaProducerSettings
settings = BaseKafkaProducerSettings(bootstrap_servers="localhost:9092")
topics = [TopicConfig(name="events", num_partitions=3, replication_factor=1)]
async with producer_lifecycle(settings, topics=topics, auto_create_topics=True) as producer:
# dicts are serialised to JSON; keys must already be bytes
await producer.send_and_wait("events", {"event": "user_created", "user_id": "123"})
producer_lifecycle yields aiokafka's own AIOKafkaProducer, started, and stops it when the
block exits — including when the block raises.
Consumer
from aiokafka_foundation_kit import consumer_lifecycle
from aiokafka_foundation_kit.contrib.models import BaseKafkaConsumerSettings
settings = BaseKafkaConsumerSettings(
bootstrap_servers="localhost:9092",
group_id="my-group",
)
async with consumer_lifecycle(settings, topics=("events",)) as consumer:
async for message in consumer:
print(message.value) # already decoded from JSON
await consumer.commit()
enable_auto_commit defaults to False, so commit after processing to get at-least-once
delivery. The async for loop is yours to write: this library manages the client, not the
message flow.
Documentation
Full documentation at bedrock-python.github.io/aiokafka-foundation-kit.
For AI agents is the whole library on one page — the API surface, the rules that break code when they are broken, the mistakes models make, and a map of which page to fetch for the rest — written to be handed to a coding assistant.
Development
# Install dependencies
uv sync --group dev --all-extras
# Lint, format check and mypy
make check
# Run tests
make test-unit
make test
License
Apache 2.0 — see LICENSE for details.
Metadata
Release files for aiokafka-foundation-kit 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiokafka_foundation_kit-0.1.2.tar.gz | 22.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiokafka_foundation_kit-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.2 kB
Release files / aiokafka_foundation_kit-0.1.2.tar.gz
| Download URL | aiokafka_foundation_kit-0.1.2.tar.gz |
|---|---|
| Size | 22.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eac6b59abf92cb2ba14d7ab6a73bd4276a97dafd5ee23282dd2b911d38b663f2
|
|
BLAKE2b-256 checksum How to use checksums |
b8de656731fc31bb57dec346f0e43f001a054d8a45b5e6373745c33dc333c243
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","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}
|
Release files / aiokafka_foundation_kit-0.1.2-py3-none-any.whl
| Download URL | aiokafka_foundation_kit-0.1.2-py3-none-any.whl |
|---|---|
| Size | 39.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73a78b730d595d108b4681a7a0457196cf4d069881297b23092c879bf9eba81a
|
|
BLAKE2b-256 checksum How to use checksums |
711fe0ef7a10b5fc8012db0a6fa9e81276b51b7932825e3e7e1fd5958b159230
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","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}
|