WKafka v1.0.0 LTS 🚀
Professional, Decorator-based Kafka Wrapper for Python.
WKafka simplifies Apache Kafka integration by providing a high-level, intuitive API focused on developer productivity. It includes built-in support for complex data types like JSON, YAML, Images, Files, and Pydantic models, making it ideal for modern microservices, IoT, and Computer Vision pipelines.
🌟 Features
- Decorator-driven API: Minimalistic and clean message handling.
- Modern Python: Fully typed, PEP 8 compliant, supporting Python 3.9 through 3.14.
- Enterprise Security: Built-in support for SASL (PLAIN, SCRAM) and KRaft mode.
- Multimedia & File Native: Seamlessly send and receive images (OpenCV/NumPy/PIL) and arbitrary files (PDF, ZIP, TXT) via
format="file". - Type-safe Pydantic Validation: Automatic schema validation with
format="pydantic". - Manual Offset Commit: Control At-Least-Once delivery semantics with
auto_commit=Falseandmsg.commit(). - Partition Auto-scaling & Retries: Automatic topic partition scaling with
describe_topicsinspection and exponential backoff retry resilience against transientNodeNotReadyError. - Async/Await Support: Define non-blocking
async defconsumer handlers. - Professional Ops: Structured logging via
loguruand multi-version testing withtox.
📦 Installation
# Via pip
pip install wkafka
# Via poetry
poetry add wkafka
Optional snappy compression:
pip install wkafka[snappy]
🚀 Quick Start
Basic Producer & Consumer
from wkafka import WKafka
# Configures automatically via KAFKA_SERVER or defaults to localhost:9092
kafka = WKafka(bootstrap_servers="localhost:9092")
@kafka.consumer(topic="orders", format="json")
def handle_order(msg):
print(f"New order received: {msg.value}")
# Start consumers in a background thread pool
kafka.run_consumers(block=True)
# Produce with context manager safety
with kafka.producer() as p:
p.send("orders", value={"id": 123, "item": "Coffee"}, format="json")
Manual Offset Commit
@kafka.consumer(topic="transactions", format="json", auto_commit=False)
def handle_tx(msg):
# Process business logic
save_to_db(msg.value)
# Explicitly commit offset only after success
msg.commit()
Retries & DLQ Routing
@kafka.consumer(
topic="unstable_events",
format="json",
max_retries=3,
retry_delay=1.0,
dlq_topic="unstable_events.DLQ"
)
def handle_event(msg):
process_payload(msg.value)
📂 Project Structure
wkafka.core: Orchestration and base logic (WKafka,Message).wkafka.serializers: Extensible serialization system (JSONSerializer,YAMLSerializer,ImageSerializer,PydanticSerializer,FileSerializer).wkafka.controller: Backward compatibility layer for legacy code.examples/: 12 complete, production-ready example modules (01_basicthrough12_pydantic_validation).enviroment/: Production-ready Docker setups (KRaft, SASL).
🛠️ Tecnologías y Librerías Relevantes
- Python (3.9 - 3.14): Lenguaje principal de desarrollo y ejecución.
- kafka-python-ng / kafka-python: Cliente subyacente para comunicación de bajo nivel con Apache Kafka.
- OpenCV (
opencv-python) & Pillow: Procesamiento, renderizado, serialización y deserialización de imágenes. - Pydantic: Validación de esquemas y modelos de datos tipados (
format="pydantic"). - NumPy: Manejo de estructuras de datos matriciales multidimensionales para imágenes.
- PyYAML: Serialización y deserialización nativa de estructuras YAML.
- Loguru: Sistema avanzado de logging estructurado.
🧪 Unit Testing & Coverage
To run the unit test suite, calculate coverage, or execute tests inside a sandboxed Docker container:
Run Locally (pytest)
poetry run pytest tests/
Coverage Report (80% Minimum Guaranteed)
./run_coverage.sh
El script genera un informe de cobertura HTML (htmlcov/index.html) garantizando una cobertura mínima global de 80%.
Sandboxed Testing with Docker
./run_tests_docker.sh
📜 License
MIT License. Created by wisrovi.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wkafka-1.2.1.tar.gz.
File metadata
- Download URL: wkafka-1.2.1.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efb72d1ecd0e36d9f72fe75f5b78a730c46f51a2d2730c3ea09612d09dd9b5b2
|
|
| MD5 |
7a567daaaa8a33be64cb69010abd148f
|
|
| BLAKE2b-256 |
bb243561ecfbdb9d14b9f5ec45c25219c3f4250f0b0bc0b6627513308623638a
|
File details
Details for the file wkafka-1.2.1-py3-none-any.whl.
File metadata
- Download URL: wkafka-1.2.1-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db01f62048f2dcc0309159280c661c5f7082a3b72d0a2c6e0e609998b2cd5073
|
|
| MD5 |
0eff1f678d1063a4ecaa9276e2790717
|
|
| BLAKE2b-256 |
ba0d56ea98d6ff186601b6bb78fc6d7c775bc0d8fd36211cffb6c560d8e254e5
|