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 # unit tests, no Docker required
make test # unit + integration tests, requires Docker
License
Apache 2.0 — see LICENSE for details.
Metadata
Release files for aiokafka-foundation-kit 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiokafka_foundation_kit-0.2.0.tar.gz | 26.3 kB | Without provenance | Details for aiokafka_foundation_kit-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiokafka_foundation_kit-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for aiokafka_foundation_kit-0.2.0-py3-none-any.whl |
Total release size: 69.5 kB
Release files / aiokafka_foundation_kit-0.2.0.tar.gz
| Download URL | aiokafka_foundation_kit-0.2.0.tar.gz |
|---|---|
| Size | 26.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
575a87a9951941d1f06f7cbf5073ef0cd49ce980770eb73c018f8a9a968f4cd2
|
|
BLAKE2b-256 checksum How to use checksums |
fe9237a8d2f3591e26ce929f4c80b895823b22ecd2af29591294ed5b66705a6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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.2.0-py3-none-any.whl
| Download URL | aiokafka_foundation_kit-0.2.0-py3-none-any.whl |
|---|---|
| Size | 43.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3e40bde23b9a552030509559cb77588334963ed3d7bd03d58d7f025096a5a092
|
|
BLAKE2b-256 checksum How to use checksums |
2ad9c5b52dee7b2c516c759c741af1571d260a82f5c4ee42b2c9cb0edbeb99ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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}
|
Security for aiokafka-foundation-kit 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.