pronto-kafka
Async Kafka producer/consumer helpers for FastAPI (and any async Python) projects. Wraps aiokafka with a module-level producer, context-manager consumers, and ready-made FastAPI lifespan hooks.
Installation
pip install pronto-kafka
Quick start — FastAPI producer
from fastapi import FastAPI
from pronto_kafka.v1 import make_producer_lifespan, send
app = FastAPI(lifespan=make_producer_lifespan("KAFKA_BOOTSTRAP_SERVERS"))
@app.post("/orders")
async def create_order(order: dict):
import json
await send("orders", json.dumps(order).encode())
return {"status": "queued"}
Set your bootstrap servers in the environment:
KAFKA_BOOTSTRAP_SERVERS=localhost:9092
Pass any env var name to make_producer_lifespan — MY_KAFKA_SERVERS, whatever fits your project.
Quick start — consumer
from pronto_kafka.v1 import create_consumer_from_env
async def process_orders():
async with create_consumer_from_env("orders", group_id="order-svc") as consumer:
async for msg in consumer:
print(msg.topic, msg.value)
Quick start — consumer as FastAPI background task
from fastapi import FastAPI
from pronto_kafka.v1 import make_consumer_lifespan
async def handle(msg):
print(f"received: {msg.value}")
app = FastAPI(
lifespan=make_consumer_lifespan(
"orders",
group_id="order-svc",
handler=handle,
)
)
Producer API
make_producer_lifespan(env_var="KAFKA_BOOTSTRAP_SERVERS", **kwargs)
Returns a FastAPI-compatible lifespan that starts the producer on startup and stops it on shutdown. Extra kwargs are forwarded to AIOKafkaProducer.
init_producer(bootstrap_servers, **kwargs)
Start the module-level producer with an explicit bootstrap-servers string.
init_producer_from_env(env_var="KAFKA_BOOTSTRAP_SERVERS", **kwargs)
Start the producer by reading bootstrap servers from an environment variable. Raises RuntimeError if the variable is missing or empty.
close_producer()
Stop and tear down the module-level producer.
get_producer() -> AIOKafkaProducer
Return the active producer instance. Raises RuntimeError if not initialised.
send(topic, value=None, key=None, headers=None, partition=None, **kwargs) -> RecordMetadata
Convenience wrapper around producer.send_and_wait(...). Raises RuntimeError if the producer is not initialised.
meta = await send("events", b'{"type": "login"}', key=b"user-42")
print(meta.topic, meta.partition, meta.offset)
Consumer API
create_consumer(*topics, group_id, bootstrap_servers, **kwargs)
Async context manager that yields a started AIOKafkaConsumer. Stops the consumer on exit.
async with create_consumer("orders", group_id="svc", bootstrap_servers="localhost:9092") as consumer:
async for msg in consumer:
process(msg)
create_consumer_from_env(*topics, group_id, env_var="KAFKA_BOOTSTRAP_SERVERS", **kwargs)
Same as create_consumer but reads bootstrap servers from an environment variable.
make_consumer_lifespan(*topics, group_id, env_var="KAFKA_BOOTSTRAP_SERVERS", handler, **kwargs)
Returns a FastAPI-compatible lifespan that runs a consumer loop as an asyncio background task. Supply a handler async function that receives each ConsumerRecord.
async def handle(msg):
await process(msg.value)
app = FastAPI(lifespan=make_consumer_lifespan("orders", group_id="svc", handler=handle))
Manual lifespan (without helpers)
from contextlib import asynccontextmanager
from fastapi import FastAPI
from pronto_kafka.v1 import init_producer_from_env, close_producer
@asynccontextmanager
async def lifespan(app):
await init_producer_from_env("KAFKA_BOOTSTRAP_SERVERS")
yield
await close_producer()
app = FastAPI(lifespan=lifespan)
Development
pip install -e ".[dev]"
pytest
Integration tests run automatically when KAFKA_BOOTSTRAP_SERVERS is set (e.g. a local Docker Kafka), otherwise they are skipped.
Versioning
Versions are derived from git tags via hatch-vcs.
git tag v0.1.0
hatch build
Metadata
Release files for rigolo 0.0.1
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 | |
|---|---|---|---|---|
| rigolo-0.0.1.tar.gz | 10.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rigolo-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.8 kB
Release files / rigolo-0.0.1.tar.gz
| Download URL | rigolo-0.0.1.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13b6dccd85c836954bba855cec1a688e84f7f2723c1e7fb0162b9a7993738cf4
|
|
BLAKE2b-256 checksum How to use checksums |
cd0f8d1fa215bc709dbfee3ad5a3a086be7a5d4658a27e98c16d39b5397f8f1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2026.
Transparency logRelease files / rigolo-0.0.1-py3-none-any.whl
| Download URL | rigolo-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2db61a123f89114b04fd96e6b3a2fc27eba55879a2a281e3a165c886889a030
|
|
BLAKE2b-256 checksum How to use checksums |
d2727ddf25bd2ce5881c70869eb3b01525e941c4a0c62457ca863d4d20022e90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2026.
Transparency logSecurity for rigolo 0.0.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for rigolo-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2026.
Transparency logA 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.