Skip to main content
image

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=False and msg.commit().
  • Retries & Dead Letter Queue: Automatic exponential backoff retries and DLQ routing (max_retries, dlq_topic).
  • Multi-Topic & Regex Subscription: Subscribe to topic lists (topic=["a", "b"]) or patterns (pattern="sensor_.*").
  • Async/Await Support: Define non-blocking async def consumer handlers.
  • Professional Ops: Structured logging via loguru and multi-version testing with tox.

📦 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_basic through 12_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

./run_coverage.sh

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

wkafka-1.0.2.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wkafka-1.0.2-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file wkafka-1.0.2.tar.gz.

File metadata

  • Download URL: wkafka-1.0.2.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.5

File hashes

Hashes for wkafka-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b0d7c25be44df3d872182333fe549b9e0303581f87361b2949d338b36ce3209f
MD5 df53bde53f469990b9da4e0ad585e4ec
BLAKE2b-256 f9caa4c01a16b5c80beb17af478f0b292aa2a89eca595a85102345aef7f80019

See more details on using hashes here.

File details

Details for the file wkafka-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: wkafka-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.5

File hashes

Hashes for wkafka-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 23fae6daa500452fe2e434ce80b32d2d4b6a1d128c67eaeb150d3487f14c654f
MD5 01e1d75b118ed7b0864951bd377dc8b9
BLAKE2b-256 0d2a626721791a1abc9edb3d327d1fb9bbf37f0a1b8965e3fe8a682e74c1f1a2

See more details on using hashes here.

Release history Release notifications | RSS feed

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.9

2 files

1.0.9

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

This release

1.0.2 This release

2 files

1.0.1

2 files

1.0.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page