aiokafka-foundation-kit
Async Kafka foundation library — settings, client factories, lifecycle helpers, topic management and DI wiring on top of aiokafka.
[!TIP] Building this with an AI assistant? Hand it one page instead of the whole site: the public API with every settings field and its real default, the producer and consumer lifecycle and commit semantics, the rules that break code when they are broken, the mistakes models actually make with this API, and a map of which page to fetch for the rest. Every docs page is also served as raw Markdown at its own URL, and a Copy page button at the top of each one hands it straight to a chat window.
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.3
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.3.tar.gz | 24.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiokafka_foundation_kit-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 65.0 kB
Release files / aiokafka_foundation_kit-0.1.3.tar.gz
| Download URL | aiokafka_foundation_kit-0.1.3.tar.gz |
|---|---|
| Size | 24.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21d2edb6ee471cf423da2172c8d7845bc21f40bde4d48f2bc98e2885f185b325
|
|
BLAKE2b-256 checksum How to use checksums |
a54c1ddc0e1ba6008e1f89742956e1fbe247b4d644a5cdf482f91fc855eda962
|
| 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.3-py3-none-any.whl
| Download URL | aiokafka_foundation_kit-0.1.3-py3-none-any.whl |
|---|---|
| Size | 40.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce88b6ec59e11a214fbbf2fcca80e32c21eb7593f414232a5aad839d73a2647f
|
|
BLAKE2b-256 checksum How to use checksums |
113dfd7da310f039376378fe9a2cd68f14bb3ce36ef8db38a9e150826e46715e
|
| 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}
|